Ebay Oauth无法获取令牌

时间:2018-09-18 07:05:13

标签: oauth ebay ebay-api

我正在尝试集成由David Sadler开发的Ebay SDK,该SDK位于github中。链接是-> https://github.com/davidtsadler/ebay-sdk-examples但我卡在连接部分本身上。我的生产凭证中包含http://localhost/ebay-sdk-examples/oauth-tokens/01-get-app-token.php的应用令牌。

但是当我打        http://localhost/ebay-sdk-examples/oauth-tokens/02-get-user-token.php它给了我这个错误

      [error] => invalid_grant
      [error_description] => the provided authorization grant code is invalid or was issued to another client

all这些代码在sdk链接中可用。如果您需要的是代码段

    <?php
    /**
     * Copyright 2017 David T. Sadler
     *
     * Licensed under the Apache License, Version 2.0 (the "License");
     * you may not use this file except in compliance with the License.
     * You may obtain a copy of the License at
     *
     * http://www.apache.org/licenses/LICENSE-2.0
     *
     * Unless required by applicable law or agreed to in writing, software
     * distributed under the License is distributed on an "AS IS" BASIS,
     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     * See the License for the specific language governing permissions and
     * limitations under the License.
     */

    /**
     * Include the SDK by using the autoloader from Composer.
     */
    require __DIR__ . '/../vendor/autoload.php';

    /**
     * Include the configuration values.
     *
     * Ensure that you have edited the configuration.php file
     * to include your application keys.
     */
    $config = require __DIR__ . '/../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['production']['credentials'],
        'ruName' => $config['production']['ruName'],
        'sandbox' => false,
    ]);
    $token = $config['production']['testToken']; ** This is the app token I get with  http://localhost/ebay-sdk-examples/oauth-tokens/01-get-app-token.php **

    /**
     * Create the request object.
     */
    $request = new Types\GetUserTokenRestRequest();
    $request->code = $token;
    // $request->code = 'v^1.1#i^1#I^3#r^1#p^3#f^0#t^Ul41XzA6MkIzRjJFRjA1MENDMzZCQjlGMjVERkYyMkMxMTRBM0VfMV8xI0VeMjYw';

    /**
     * Send the request.
     */
    $response = $service->getUserToken($request);

    echo '<pre>';
    print_r($response);
    echo '<pre>';
    exit;

    /**
     * Output the result of calling the service operation.
     */
    printf("\nStatus Code: %s\n\n", $response->getStatusCode());
    if ($response->getStatusCode() !== 200) {
        printf(
            "%s: %s\n\n",
            $response->error,
            $response->error_description
        );
    } else {
        printf(
            "%s\n%s\n%s\n%s\n\n",
            $response->access_token,
            $response->token_type,
            $response->expires_in,
            $response->refresh_token
        );
    }

任何帮助都将受到高度赞赏。或者,如果有简单的代码,而无需使用任何SDK通过oauth连接到ebay,那就是我要搜索的内容。谢谢。

2 个答案:

答案 0 :(得分:0)

我目前也在使用此SDK。

我的理解是您应该放置网址:

from flask_socketio import SocketIO
import datetime
import time    

socketio = SocketIO(message_queue='redis://')    

if __name__ == '__main__':
    while True:
        msg = datetime.datetime.now().strftime("%a, %d %b %Y %H:%M:%S")
        print(msg)
        socketio.emit('message', msg, broadcast=True)
        time.sleep(1)

作为您的auth在developer.ebay.com中接受的URL1,在“通过您的应用程序从eBay获取令牌”下。

在您设置$ token的位置,应将其设置为$ _GET ['code'],因为在测试登录并接受您时,应将其重定向到上述URL,并解析回它为?code = xxxx。 / p>

您当前设置为$ token的值应设置为凭据中authToken的值。

希望有帮助。

答案 1 :(得分:0)

eBay令牌生成可以使用我们的自定义PHP / .NET脚本来实现。具有许多参考的eBay API文档

https://viewdotnet.wordpress.com/2011/12/20/ebay-token-generation/

以上链接包括生成eBay身份验证所需的所有详细信息。令牌