设置 curl header 以获取令牌

Set a curl header for getting tokens

我想设置一个 header 以从 flipkart 获取令牌。我不知道如何在 curl 中设置 header。我的header应该喜欢

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

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

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

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

有关详细信息,请参阅 curl documentation on curl_setopt

在 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 和密码。不要存储访问令牌,它会在特定时间段内过期。

link 对于 api 文档 - “https://seller.flipkart.com/api-docs/fmsapi_index.html