我正在尝试在c#中为Pushbullet API复制这个Curl调用。
curl https://api.pushbullet.com/v2/pushes
-u <your_api_key_here>:
-d device_iden="<your_device_iden_here>"
-d type="note"
-d title="Note title"
-d body="note body"
-X POST
下面是我复制它的代码:
var response = default(IRestResponse);
var request = new RestRequest(Method.POST) { RequestFormat = DataFormat.Json };
var client = new RestClient();
client.BaseUrl = "https://api.pushbullet.com/v2/";
request.Resource = "pushes";
var bodyInformation = string.Concat(" { "", Config.Settings.PushbulletAPIKey,
"": { "type":"note", "title":"", title, "", "body":"", message, "" } }");
request.AddBody(bodyInformation);
response = client.Execute(request);
当我发送它时,它返回这个:
{"error": {"message": "authentication token is missing or invalid.", "type": "invalid_user"}}
参考API页面:
https://docs.pushbullet.com/https://docs.pushbullet.com/v2/pushes您在body内部传递凭据,而不是设置客户端的Authenticator
属性以使用基本身份验证来传递凭据。
curl -u
交换机使用username:password凭证对服务器进行基本认证。您发布的语句使用API密钥作为用户名和空密码。
你应该这样写:
client.Authenticator = new HttpBasicAuthenticator(
Config.Settings.PushbulletAPIKey, "");