【问题标题】:Set a curl header for getting tokens设置 curl 标头以获取令牌
【发布时间】:2016-03-15 04:41:23
【问题描述】:

我想为从 Flipkart 获取令牌设置一个标题。我不知道如何在 curl 中设置标题。我的标题应该喜欢

curl -u <appid>:<app-secret> https://sandbox-api.flipkart.net/oauth-service/oauth/token\?grant_type\=client_credentials\&scope=Seller_Api

【问题讨论】:

  • 我正在尝试相同的方法,但我得到的是空字符串,请帮忙。

标签: php curl flipkart-api


【解决方案1】:

看起来您正在尝试进行 HTTP 基本身份验证,或者至少这是 curl 的 -u 选项在像这样单独使用时所做的事情。

在 PHP 中,您将为这样的 curl 请求设置基本身份验证,假设 $ch 是您的 curl 实例(您可以使用 curl_init 获得):

curl_setopt($ch, CURLOPT_USERPWD, 'appid:appsecret');

请参阅curl documentation on curl_setopt 了解更多信息。

【讨论】:

    【解决方案2】:

    在 curl 命令中你必须这样做,

    curl -u your-app-id:your-app-token https://sandbox-api.flipkart.net/oauth-service/oauth/token\?grant_type\=client_credentials\&scope=Seller_Api
    

    成功后你会得到这样的结果,

    {"access_token":"394b7d-418a-43f6-8fd5-e67aea2c4b","token_type":"bearer","expires_in":4657653,"scope":"Seller_Api"}
    

    通过使用此令牌,您可以进行进一步的 api 调用,例如列出 api,

    curl -H "Authorization:Bearer your-access-token" -H "Content-Type: application/json" -d 'json-here-see-format-in-api-example' https://url-end-point-refer-api-docs
    

    注意:您必须在“https://sandbox-api.flipkart.net/oauth-register/login”中为沙盒创建应用程序 ID 和密码。不要存储访问令牌,它会在一段时间内过期。

    api 文档的链接 - "https://seller.flipkart.com/api-docs/fmsapi_index.html"

    【讨论】:

      猜你喜欢
      • 2017-07-25
      • 2014-11-22
      • 2013-12-24
      • 2019-11-29
      • 2021-07-27
      • 1970-01-01
      • 1970-01-01
      • 2019-07-22
      • 2019-11-26
      相关资源
      最近更新 更多