What OAuth 1 or 2 should I choose in order to perform campaign analytics?

oauth
analytics

#1

Hello everybody,

Our company is interested to advertise on Twitter.
We would like to start campaign and study its performance.
I’m a SAS programmer and I’m going to perform these estimations.
But first of all I need to connect to Twitter using CUrl(or TwUrl) and retrieve the data for analysis.
I’m going to automate this process and produce BI report for our managers.

As I saw all examples in “Analytics” section applies to OAuth 1.1
https://dev.twitter.com/ads/analytics/best-practices
It’s a way complicated than OAuth2 (application authentication).
Please advice what type of authentication to use and please provide a sample code.
I prefer the OAuth2 but there are no links for it in “Analytics” section.

I’ve tried to connect using OAuth1 as it’s described here:
http://oauth.net/core/1.0/#anchor9
But I don’t know to pass the step with PIN in automatic process…

Please advise.

Sincerely,
Alex Fedorov


#2

Both 1 and 2 are necessary


#3

Jesmion, thank you for your answer.

Could you please provide some example for 2-legged approach (OAuth 1.0a)?

I get lost in documentation and I cannot perform a very basic task, to retrieve data for my analytics.

May I have link for STAS which works with OAuth2?
(instead of this none: https://ads-api.twitter.com/0/stats/accounts/:account_id)


#4

UPDATES:

I’ve already registered an OAuth application
to get a consumer key and secret:
https://apps.twitter.com/app/new

We went with OAuth 1.0a

We have installed the TWURL (https://github.com/twitter/twurl)

I was able to get the PIN using link from this command :
twurl authorize --consumer-key key --consumer-secret secret

Got:
Authorization successful.


QUESTION:
How to enable xAuth in order to perform authentication in one step, as shown here? :

% twurl authorize -u username -p password
–consumer-key key
–consumer-secret secret


#5

Jesmion,

For my question about what OAuth (1.0a or 2) to prefer, I’ve found this:

Ads API does not support app-only authentication. User context is required for all Ads API activity. Here’s some more info: https://dev.twitter.com/ads/campaigns#HTTP_OAuth37


SO the OAuth 2.0 is not applicable for using Analytics (ads-api).


#6

We can confirm that all analytics endpoints on the Ads API require User-Context, and therefore OAuth 1.0A. See more here: https://dev.twitter.com/ads/overview/getting-started#HTTP_OAuth


App-Only access to Ads API?
#7

Thanks Jaakkosf,

I understood this fact by myself and reflected it in my last comment in bold font.

The unanswered question still remains:

"QUESTION:
How to enable xAuth (or smth. else) in order to perform authentication in one step, as shown here? :

% twurl authorize -u username -p password
–consumer-key key
–consumer-secret secret"

Thanks in advance,
I appreciate your help.


#8

The xAuth documentation specifies how to request access.


#9

@Marketsdotcom, we do not grant xauth access for any applications that utilize the Ads API. You must use OAuth 1.0A. That means a 3-legged auth flow to get your auth tokens for a user. Once you have those, it’s a single OAuth 1.0A signing that you’ll need to do for each API call.


#10

Jaakkosf,

Could you please provide an example in TwURL for " it’s a single OAuth 1.0A signing that you’ll need to do for each API call."
Here I understand I need use the token I got in a first 3-legged auth.

Thanks in advance!


#11

@Marketsdotcom this is what twurl does (its the tool’s entire purpose). Any example with twurl will perform an OAuth 1.0a signed request for you.

For example:

twurl -H ads-api.twitter.com "/0/accounts"
twurl -X DELETE -H ads-api.twitter.com "/0/accounts/12345/campaigns/12345"
twurl "/1.1/statuses/home_timeline.json"

All of the above examples produce OAuth 1.0a signed requests to those endpoints. OAuth 1.0a is actually pretty straight-forward and there are many examples of how to use it available. I’d recommend a re-read of the links to our OAuth documentation provided previously.

https://dev.twitter.com/oauth
https://dev.twitter.com/oauth/3-legged
https://dev.twitter.com/ads/overview/obtaining-ads-account-access


#12