ahmad
#1
Hi Team,
Quick question - I have a developer account and I am able to use the Twitter Ads Analytics API but now I also need the organic data (impressions, engagement etc which I can’t get from Metrics Metrics | Docs | Twitter Developer Platform ) - how to check if I have the Engagement API (Engagement API | Twitter API | Docs | Twitter Developer Platform) access before raising a request with the sales team ?
can anyone guide me please .
The Engagement API is a commercial (Enterprise) product, so you would already have an agreement in place around that, and credentials for access to it - these differ from the OAuth tokens you use for the Ads API.
You may want to take a look at the Twitter API v2 which has some of this metrics information. In order to access metrics like impressions, you will need the user’s access token for the account you want to check.
ahmad
#3
thanks for the quick response @andypiper . Well yes, I did use the highlighted Twitter API V2 go get the public metric using Bearer $BEARER_TOKEN for authorisation but couldn’t find any example as to how to access organic and promoted metrics (data.organic_metrics.impression_count) which we need for the twitter account. Any guidance or sample for that ? ( we do have CONSUMER_KEY /CONSUMER_SECRET / ACCESS_TOKEN and ACCESS_TOKEN_SECRET) but not sure how to frame the request for accessing the Non-public, organic and promoted metrics.
For v2 we have a variety of samples, but you will need to make modifications for your own use to access those metrics. One example is this Python code which accesses an individual Tweet (after requesting a user access token in code - you could skip that step and directly insert the access token and secret values). You would need to include the relevant tweet.fields in your request, as well. I don’t have a single example that does everything end-to-end at the moment.
ahmad
#5
thanks @andypiper - I will give it a try . Can you also share and example or reference as how to get all the tweet ids for an account ? as I reckon that is the first step needed to fire the v2 request
Look at the User Tweet timeline sample in the same GitHub repo.
1 Like
ahmad
#7
HI @andypiper - tried the Python code you shared above(1) but it still doesn’t return the organic metrics I am after - attached screenshot of the response.
I do have ANALYST (“Organic Analyst”) permission for the account I am trying to pull organic metrics for.
Kinda urgent - can you please guide -
params = {“ids”: “1440927300397289473”, “tweet.fields”: “organic_metrics”}
ahmad
#8
hi @andypiper /twitter team - can you or anyone please guide us . This has become a bottleneck for us in meeting the delivery.
full code
from requests_oauthlib import OAuth1Session
# Make the request
oauth = OAuth1Session(
CONSUMER_KEY,
client_secret=CONSUMER_SECRET,
resource_owner_key=ACCESS_TOKEN,
resource_owner_secret=ACCESS_TOKEN_SECRET,
)
params = {"ids": "1430470871110627332", "tweet.fields": "organic_metrics"}
response = oauth.get(
"https://api.twitter.com/2/tweets", params=params
)
response.text
Trying to access the organic_metrics for this tweet from our own account - I even gave the developer handle account admin access but still of no use - same error for (organic / non_public and promoted_metrics) https://twitter.com/datarunsdeep/status/1430470871110627332
I know the tokens are correct coz using the same I am able to get success response for other endpoints for e.g. reach/ frequency etc. Why is organic an issue ?
Things to check (these are all in the documentation about metrics in v2)
- The Tweet must be from within the past 30 days. It it not possible to access these metrics from older Tweets.
- You must be using the access token and secret for the account that posted the Tweet in order to access
organic and non_public metrics.
- Ensure that you have specified the correct metrics
tweet.fields and any expansions that you require
Note that this is a different API to the Ads API, so permissions from Ads (“Organic Analyst”) are not relevant here.
1 Like
system
Closed
#10
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.