Hi,

I’m having a trouble of POSTing scheduled tweets from the twitter app I develop for my client.
My client’s ads account is granted access in my ads account. Please see the “Screenshot 1”
Also I have created a paid campaign in my ads account with just USD 1$, just for testing for now. Please see “Screenshot 2” and “Screenshot 3”.
Then I tried to execute below API. And got the result correctly.

Requst:-
https://ads-api.twitter.com/10/accounts

Response:-
{“request”:{“params”:{}},“next_cursor”:null,“data”:[{“name”:“Tweetvio”,“business_name”:null,“timezone”:“Africa/Lagos”,“timezone_switch_at”:“2021-09-18T23:00:00Z”,“country_code”:“NG”,“id”:“18ce55foxxi”,“created_at”:“2021-09-20T11:47:13Z”,“updated_at”:“2021-10-05T15:36:46Z”,“industry_type”:null,“business_id”:null,“approval_status”:“ACCEPTED”,“deleted”:false},{“name”:“LasaNisaAds”,“business_name”:null,“timezone”:“Asia/Karachi”,“timezone_switch_at”:“2021-09-28T19:00:00Z”,“country_code”:“LK”,“id”:“18ce55frbi9”,“created_at”:“2021-09-28T14:39:22Z”,“updated_at”:“2021-10-11T06:39:32Z”,“industry_type”:“OTHER”,“business_id”:null,“approval_status”:“ACCEPTED”,“deleted”:false}]}

Then I tried to execute below API to POST a scheduled tweet. And it errored as below.

Request:-
https://ads-api.twitter.com/10/accounts/18ce55foxxi/scheduled_tweets?as_user_id=182328584&scheduled_at=2021-10-12T11:30:00&text=Test

Error:-
{“errors”:[{“code”:“UNAUTHORIZED_ACCESS”,“message”:“This request is not properly authenticated”}],“request”:{“params”:{}}}

For both requests, I used the same authentication tokens.
18ce55foxxi is my client’s ads account id.
182328584 is the user_id of my twitter account “LasaNisa”

Please have a look and let me know why POST request gives this error.
Thanks,
Lasantha

Applications can get an UNAUTHORIZED_ACCESS if the authentication headers aren’t properly build. In this case, I suspect the application is not properly encoding the scheduled_at field. We strongly recommend using an existing 3rd Party library that implements support for building OAuth 1.0a headers.

Could you try the request above using Twurl and let me know if this succeeds?

Hi,
I used the same url with the " scheduled_at" value with ending Z character as below.

https://ads-api.twitter.com/10/accounts/18ce55foxxi/scheduled_tweets?as_user_id=182328584&scheduled_at=2021-10-12T11:30:00Z&text=Test

But same error came.

Can you please confirm the below points I have doubts on.

  1. Is it must a paid campaign in twitter ads account, that I used to logged in to “tweetvio” for test this scheduled tweet POST? I already gave access grant from my “lasanisa” account to “wolexfeelcool” account that belongs to my client.

  2. I’m using “RestSharp.RestClient” NuGet package to create the restclient with OAuth 1.0 authentication as below. Please let me know, this authentication is correct? This work for GET request.

RestClient restClient = new RestClient(“https://ads-api.twitter.com”);
restClient.Authenticator = OAuth1Authenticator.ForAccessToken(
this._configuration.GetValue(“TwitterAPIKey”),
this._configuration.GetValue(“TwitterAPISecretKey”),
this._httpContextAccessor.HttpContext.Session.GetString(“OAuthToken”),
this._httpContextAccessor.HttpContext.Session.GetString(“OAuthTokenSecret”),
RestSharp.Authenticators.OAuth.OAuthSignatureMethod.HmacSha1);

Also we have other Signature methods “HmacSha256”, “PlainText”, and “RsaSha1”.

  1. I show in one place of this community questions, there was an answer like below, by “carmenjyuen”. Can you please let me know whether I don’t have write permission to POST tweets by API.

You indicated that you are trying to build an analytics connection, so you only have read-only permissions to the Ads API. According to the error, you are trying to make a write call.

Can you explain more about what call you are trying to build, and if you do need to have write permissions?

Best,
Carmen

Please have a look…

Thank,
Lasantha

Also,
When I tried TwUrl as below.
TwUrl https://ads-api.twitter.com/10/accounts/18ce55foxxi/scheduled_tweets?as_user_id=182328584&scheduled_at=2021-10-12T11:30:00Z&text=Test

It gave the error.
‘scheduled_at’ is not recognized as an internal or external command

When I used Twurl as below,
1)
TwUrl https://ads-api.twitter.com/10/accounts/18ce55foxxi/scheduled_tweets?as_user_id=182328584&text=Test

Error:-‘text’ is not recognized as an internal or external command.

TwUrl https://ads-api.twitter.com/10/accounts/18ce55foxxi/scheduled_tweets?as_user_id=182328584

Error:- Invalid URI detected.

Hi… Please can any one confirm the above 3 points?

The errors reflect invalid command line arguments. Here is an example

twurl -H “ads-api.twitter.com” “/7/accounts”

For the scheduled Tweet, here is what the command should look like:

twurl -H "ads-api.twitter.com" "/10/accounts/18ce55foxxi/scheduled_tweets?as_user_id=182328584&text=Test&scheduled_at=2021-10-12T11:30:00Z" -X post

Hi osowskit1,

Thank you for replying with the correct way of sending this POST request via twurl.
I did it exactly in twurl just now, as the way you mentioned.
And it gave the same error below. (I don’t see a place here to attach the screenshot of cmd with twurl command and error I got)

{“errors”:[{“code”:“UNAUTHORIZED_ACCESS”,“message”:“This request is not properly authenticated”}],“request”:{“params”:{}}}

So I suspect the reason must be the point (3) I mentioned in previous message.

=============================================================
3. I show in one place of this community questions, there was an answer like below, by “carmenjyuen”. Can you please let me know whether I don’t have write permission to POST tweets by API.

You indicated that you are trying to build an analytics connection, so you only have read-only permissions to the Ads API. According to the error, you are trying to make a write call.

Can you explain more about what call you are trying to build, and if you do need to have write permissions?

Best,

Carmen

Can you please let me know, how can I get the write permission?
Or do you think any other reason for the issue?
Please guide…

Thanks,
Lasantha

Hi,

I tried with both “RestSharp” and “OAuth” to build OAuth1 headers.
Both ways gave the same error below.

{“errors”:[{“code”:“UNAUTHORIZED_ACCESS”,“message”:“This request is not properly authenticated”}],“request”:{“params”:{}}}

What could be the the reason?
Please guide…

Thanks,
Lasantha

Hi,

Today I could do something like this.
I first deleted the existed twurlrc file from my user folder. Because, It had more than one credential sets saved.
Then I ran the “twurl authorize” command newly. It generated the new twurlrc file again. Then I ran the schedule tweet command and got this permission message.

{“errors”:[{“code”:“INSUFFICIENT_CLIENT_APPLICATION_PERMISSION”,“message”:“This
client application does not have permission to make write requests”}],“request”:
{“params”:{}}}

Please see the screen shot.
Please grant write permission to the ads-api for this app “wolexfeelcool”

image

Thanks,
Lasantha

@carmenjyuen Here is my details

Owner ID - 71785706
App ID - 21531391

kindly grant write access and whitelist app. Thank you

Hi osowskit1,

My client “wolexfeelcool” has requested to get write access in ads api.
Please have a look when you got a free time.
Below is my client’s message.

==============================================
@carmenjyuen Here is my details

Owner ID - 71785706
App ID - 21531391

kindly grant write access and whitelist app. Thank you

Thanks…