设置用于获取令牌的卷曲标头


Set a curl header for getting tokens

我想设置一个标头,用于从flipkart获取令牌。我不知道如何在卷曲中设置标题。我的标题应该喜欢

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_setopt 上的 curl 文档。

在 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"