Hello, community!

I created an App, grant it access (Read + Write + Read and post direct messages), created a dev environment, set the environment to Account Activity API to get access to the sandbox. Now I try to check API using postman. (postman and twitter gem in my case)

For checking access I used:

  1. GET /1.1/account/verify_credentials.json - responded 200 with data;
  2. GET /1.1/account_activity/all/webhooks.json - responded 200 with data; No hooks registered;
  3. Then I try to register webhook using: POST /1.1/account_activity/all/dev/webhooks.json?url=https://{mynumbers}ngrok.io- and get 401 “Could not authenticate you.”
1 Like

Is the ngrok.io url added to the app configuration in Callback URLs?

Also, how exactly are you authenticating calls? Because GET account_activity/all/webhooks is Bearer (app only) token while POST /1.1/account_activity/all/dev/webhooks.json requires user auth (access token + secret) Premium Account Activity API | Docs | Twitter Developer Platform

1 Like
  1. in which input field should be this ngrok url? WEBSITE URL? or CALLBACK URLS?
    And should it be just like that https://{mynumbers}ngrok.io or https://{mynumbers}ngrok.io/twitter_callback?

  2. GET account_activity/all/webhooks I authenticated with bearer, but POST I authenticated with “OAuth oauth_consumer_key…” same as verify_credentials.json - which is returning 200 OK

2 Likes

Yeah - it should be in Callback URLs, and /twitter_callback depends on how your server is set up to respond - eg, this one is /listener GitHub - twitivity/twitivity: Twitter Accounts Activity API Client Library for Python other code may have a different route.

2 Likes

Yeah, this is exactly how I established it. Does not work.

1 Like

What language / library are you using - do you have code samples? Was it in Ruby with twitter gem or in postman?

Does it work if you use an alternative implementation? GitHub - twitterdev/account-activity-dashboard: Sample web app and helper scripts to get started with the premium Account Activity API (I know for sure this code works)

1 Like

I’m using this gem and postman

postman request is:

POST /1.1/account_activity/all/deve/webhooks.json?url=https://4e42e128642e.ngrok.io/webhook/twitter HTTP/1.1
Host: api.twitter.com
Authorization: OAuth oauth_consumer_key="CONSUMER_KEY",oauth_token="TWITTER_ACCESS_TOKEN",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1628075146",oauth_nonce="OAUTH_NONCE",oauth_version="1.0",oauth_signature="OAUTH_SIGNATURE"
cache-control: no-cache
Postman-Token: 7f518f41-215b-4be6-9b14-01b20fa31131

I have 'https://4e42e128642e.ngrok.io/webhook/twitter’ in CALLBACK URLS and I have this route in my app. But got 401.

I tried account-activity-dashboard and it worked. I cannot understand this part:

1. Take note of the deployed URL, revisit your developer.twitter.com Apps **Settings** page, and add the following URL values as whitelisted Callback URLs:


http(s)://your.app.domain/callbacks/addsub
http(s)://your.app.domain/callbacks/removesub

But sending the request with https://your.app.domain/webhook/twitter

May be this is somehow related

2 Likes

This part is needed to add the extra urls to callback URLs in the app settings - that’s just how the code was written, it may be different in a different implementation.

It’s hard to say what’s missing where - but if account-activity-dashboard is working for you, then it may be worth going back over your code to see what the differences are - maybe a url or parameter is not being encoded correctly or something?

I just remembered there’s a good Ruby example in this repo SnowBotDev/setup_webhooks.rb at master · twitterdev/SnowBotDev · GitHub this part sets up a webhook - maybe it will help too

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.