使用 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)