我目前正在尝试使用OneSignal REST API。我想使用GET方法来调用View Apps操作:
我已尝试使用自己的APP_ID将PowerShell与以下命令配合使用:
curl --include \
--header "Authorization: Basic YWUwZDhjNjAtZDQ4ZS00NWI5LWJjMzctYz" \
https://onesignal.com/api/v1/apps
它输出:
未找到接受参数\的位置参数
然后我尝试执行:
curl -X GET -H 'Content-Type: application/json' -H 'Authorization: Basic YWUwZDhjNjAtZDQ4ZS00NWI5LWJjMzctYz' -v -i 'https://onesignal.com/api/v1/apps'
它输出:
Headers参数无法链接。无法将值“ Content-Type:应用程序/ json”从类型“ System.String”转换为类型“ System.Collections.IDictionary”。
然后,我尝试使用Postman,如下所示:
我们的请求翻译成代码的位置是:
GET /api/v1/apps HTTP/1.1
Host: onesignal.com
Content-Type: application/json
Authorization: Basic YWUwZDhjNjAtZDQ4ZS00NWI5LWJjMzctYz
User-Agent: PostmanRuntime/7.19.0
Accept: */*
Cache-Control: no-cache
Postman-Token: 32a57eb1-1660-4f7b-b141-7fccf83d0851,537878c7-5135-48a8-a04a-1125824785b9
Host: onesignal.com
Accept-Encoding: gzip, deflate
Cookie: __cfduid=ded10b101ef5b9cd648b95b6d2e88f1261572874737
Connection: keep-alive
cache-control: no-cache
但是,它回答了我们:400错误的请求:
{
"errors": [
"Please include a case-sensitive header of Authorization: Basic <YOUR-USER-AUTH-KEY-HERE> with a valid User Auth key."
],
"reference": [
"https://documentation.onesignal.com/docs/accounts-and-keys#section-user-auth-key"
]
}
I have read the API documentation given in the response, and I am sure I am using the REST API KEY, as it is requested in the documentation (below an image showing how would look like a REST API KEY).
Finally I have tried a web app, to send the request as:
Where the CURL command generated is:
curl -X GET -H 'Content-Type: application/json' -H 'Authorization: Basic YWUwZDhjNjAtZDQ4ZS00NWI5LWJjMzctYz' -v -i 'https://onesignal.com/api/v1/apps'
However the response stills being:
Error
Error: Bad Request
Response: 400
headers:
{
"cache-control": "no-cache",
"content-type": "application/json; charset=utf-8"
}
body:
{
"errors": [
"Please include a case-sensitive header of Authorization: Basic <YOUR-USER-AUTH-KEY-HERE> with a valid User Auth key."
],
"reference": [
"https://documentation.onesignal.com/docs/accounts-and-keys#section-user-auth-key"
]
I have searched information, and I have read a github thread where it is advised to confirm that you are using the correct REST API KEY.
In addition I have previously read:
PowerShell equivalent of curl cURL example for accessing authenticated Kraken API
我们如何使用PowerShell或任何其他命令行工具发送GET请求request
我们如何创建格式正确的请求,如OneSignal文档中所示‽
此API端点需要您的用户身份验证密钥,而不是您的应用程序身份验证密钥。原因是此API端点是列出您所有的OneSignal应用程序,而不仅仅是特定的应用程序。
请参阅此处的文档页面,以获取有关如何获取用户身份验证密钥的详细信息:https : //documentation.onesignal.com/docs/accounts-and-keys#section-user-auth-key
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句