The remote server returned an error: (401) Unauthorized


I tried to update line item using following URL.

I used HTTP Web Request With Authorization header.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add(“Authorization”, authHeader);
request.Method = “PUT”;
request.ContentType = “application/x-www-form-urlencoded”;
request.UserAgent = “OAuth gem v0.4.4”;

My authorization header contain seven parameters as follows.

OAuth oauth_nonce=“NjM2MTM0NTIzNjIzNjI3ODY2”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1477835762”, oauth_consumer_key=“xXXXXXXXXXXXXXXXXXX”, oauth_token=“723197898305859587-XXXXXXXXXXXXXXXXXXXXXXXX”, oauth_signature=“IFHUFehnjHsFQkA0hwJgYxwNU0I%3D”, oauth_version=“1.0”

But this request not authorized by the twitter ads API. It returns “The remote server returned an error: (401) Unauthorized.” error.

Please correct me that where I am doing wrong.

Thank you …


For C# authorization, please check out the library being maintained by one of our community members called Tweetinvi:

If you want to try to create custom support it’s possible but I would recommend trying to use SDK instead.




Hi JBabich,

I have gone through the SDk Tweetinvi. It is used for the Tweeter public we are able to get tweeter public data using Tweetinvi . But when we are trying to get TwitterAds data like accounts and campaigns, we are not able to get the data. Please suggest us an SDK which will get TwitterAds api in C#.



Hi @Marala! I use PHP, not C#, and I used a library which is also only thought for the Twitter public REST API, not for Ads API, but I extended a class, overwritten the host and version and then I could make successful Ads API requests. Would it be possible for you to do the same thing using the library of Tweetinvi? Just a thought.