The remote server returned an error: (401) Unauthorized

apps.twitter.com
oauth
ads
api

#1

I tried to update line item using following URL.

https://ads-api.twitter.com/1/accounts/18ce54dd2m9/line_items/6m5b3/?paused=true

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 …


#2

For C# authorization, please check out the library being maintained by one of our community members called Tweetinvi: https://github.com/linvi/tweetinvi

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

Thanks,

John


#3

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#.

Thanks
marala


#4

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.