예제 #1
0
 private function grantOauthAccess($app_key, $secret_token)
 {
     include_once _PS_MODULE_DIR_ . 'yotpo/lib/oauth-php/library/YotpoOAuthStore.php';
     include_once _PS_MODULE_DIR_ . 'yotpo/lib/oauth-php/library/YotpoOAuthRequester.php';
     $yotpo_options = array('consumer_key' => $app_key, 'consumer_secret' => $secret_token, 'client_id' => $app_key, 'client_secret' => $secret_token, 'grant_type' => 'client_credentials');
     YotpoOAuthStore::instance('2Leg', $yotpo_options);
     try {
         $request = new YotpoOAuthRequester(self::YOTPO_OAUTH_TOKEN_URL, 'POST', $yotpo_options);
         $result = $request->doRequest(0);
         $pregResult = preg_match("/access_token[\\W]*[\"'](.*?)[\"']/", $result['body'], $matches);
         $token = $pregResult == 1 ? $matches[1] : '';
         return $token != '' ? $token : null;
     } catch (YotpoOAuthException2 $e) {
         d($e);
         return null;
     }
 }
예제 #2
0
function fn_grant_oauth_access($app_key, $secret_token)
{
    $OAuthStorePath = dirname(__FILE__) . '/lib/oauth-php/library/YotpoOAuthStore.php';
    $OAuthRequesterPath = dirname(__FILE__) . '/lib/oauth-php/library/YotpoOAuthRequester.php';
    require_once $OAuthStorePath;
    require_once $OAuthRequesterPath;
    $yotpo_options = array('consumer_key' => $app_key, 'consumer_secret' => $secret_token, 'client_id' => $app_key, 'client_secret' => $secret_token, 'grant_type' => 'client_credentials');
    YotpoOAuthStore::instance("2Leg", $yotpo_options);
    try {
        $request = new YotpoOAuthRequester(YOTPO_OAUTH_TOKEN_URL, "POST", $yotpo_options);
        $result = $request->doRequest(0);
        $tokenParams = json_decode($result['body'], true);
        if (isset($tokenParams['access_token'])) {
            return $tokenParams['access_token'];
        } else {
            return NULL;
        }
    } catch (YotpoOAuthException2 $e) {
        //Do nothing
        return NULL;
    }
}