davidtsadler / ebay-sdk-examples

Several examples of using the eBay SDK for PHP
http://devbay.net
Apache License 2.0
184 stars 100 forks source link

access token issue while creating a ebay app authorization screen #59

Closed hozyali closed 4 years ago

hozyali commented 6 years ago

Hi, for a custom ebay order management system, I need the user to authorize my app that I already created in ebay sandbox and production both. I am copying the sample code from oAuth-tokens folder and trying to setup the app authorization screen. When merging the get app auth and get user token both, the screen goes blank. Enabled error debugging as well, but nothing.

Here is my current code. Sorry I am newbie with this, I am sure I am doing something wrong.

require 'ebay-sdk-php/ebay-sdk-php-autoloader.php';
$config = require 'php-ebay/configuration.php';

/**
 * The namespaces provided by the SDK.
 */
use \DTS\eBaySDK\OAuth\Services;
use \DTS\eBaySDK\OAuth\Types;

/**
 * Create the service object.
 */
$service = new Services\OAuthService([
    'credentials' => $config['sandbox']['credentials'],
    'ruName'      => $config['sandbox']['ruName'],
    'sandbox'     => true
]);

/**
 * Send the request.
 */
$response = $service->getAppToken();
$auth_code = $response->access_token; // auth code for exchange with access token

// access token request
/**
 * Create the request object.
 */
$request_token = new Types\GetUserTokenRestRequest();
$request_token->code = $auth_code;

/**
 * Send the request.
 */
$response_token = $service->getUserToken($request_token);
print($response_token->access_token);

exit;
timramseyjr commented 6 years ago

$auth_code shouldn't be access_token, but is returned once you redirect the users to $url so they can sign in.

$url = $this->oAuthService->redirectUrlForUser([ 'state' => $state, 'scope' => [ 'https://api.ebay.com/oauth/api_scope/sell.account', 'https://api.ebay.com/oauth/api_scope/sell.inventory' ] ]);

Whatever page you put in the redirect settings in eBay will have a code variable in the url.