小编Tim*_*Tim的帖子

RestSharp 中针对 Twitter API GET 和 POST 方法的 OAuth1 身份验证

使用 Postman,我可以API使用 Postman 的 OAuth 1.0 授权成功地使用 Twitter 查询和创建定制受众。然而,当尝试使用 RestSharp 执行相同操作时,我收到未经授权的错误。

“UNAUTHORIZED_ACCESS”-“此请求未经过正确身份验证”。

我的GET请求身份验证正常,但 POST 请求失败。

        _twitterRestClient = new RestClient("https://ads-api.twitter.com/1")
        {
            Authenticator = OAuth1Authenticator.ForProtectedResource(ConsumerKey, ConsumerSecret, AccessToken, AccessSecret)
        };

        var restRequest1 = new RestRequest(string.Format("/accounts/{0}/tailored_audiences", TwitterAccountId), Method.GET);
        //this works and gives me a list of my tailored audiences
        var response1 = _twitterRestClient.Execute(restRequest1);

        var restRequest2 = new RestRequest(string.Format("/accounts/{0}/tailored_audiences?name=SampleAudience2&list_type=EMAIL", TwitterAccountId), Method.POST);
        // this results in an "Unauthorized" status code , and the message {\"code\":\"UNAUTHORIZED_ACCESS\",\"message\":\"This request is not properly authenticated\"}
        var response2 …
Run Code Online (Sandbox Code Playgroud)

twitter restsharp oauth-1.0a

2
推荐指数
1
解决办法
3239
查看次数

标签 统计

oauth-1.0a ×1

restsharp ×1

twitter ×1