Nama Keru
Nama Keru

Reputation: 1021

OAuth Authentication with Twitter API failed!

I used R's packages 'twitteR' and 'ROAuth' to access Twitter API. I tried this R code to register my R session:

tw<-OAuthFactory$new(consumerKey="mykeyhere",consumerSecret="mysecrethere",  
requestURL="http://api.twitter.com/oauth/request_token",
accessURL="http://api.twitter.com/oauth/access_token",
authURL="http://api.twitter.com/oauth/authorize")
tw<-handshake()

I used http instead of https because the latter gave me an error of SSL certification fail. Then, I enter a PIN code obtained from a given URL and registered with Twitter:

registerTwitterOAuth(tw)

The result of the above command was:

[1] TRUE

I think that I successfully registered using OAuth. However, when I tried to access protected users' profiles, for example,

getURL("http://api.twitter.com/1/followers/ids.json?cursor=-1&user_id=XXXXXXXX")

I got this:

[1] "{\"error\":\"Not authorized\",\"request\":\"\\/1\\/followers\\/ids.json?cursor=-1&user_id=XXXXXXXX\"}"

I also checked my verification by using:

getURL("http://api.twitter.com/1/account/verify_credentials.json")

And this was the result:

[1] "{\"error\":\"Could not authenticate you.\",\"request\":\"\\/1\\/account\\/verify_credentials.json\"}"

Would you mind helping me please? Thank you very much.

Upvotes: 2

Views: 2440

Answers (1)

force of love
force of love

Reputation: 36

You should use getUser(...),searchTwitter(...),tw$OAuthRequest(...) and so on instead of directly use getURL(...) by yourself because getURL() does not contain session context (which register using registerTwitterOAuth).

Upvotes: 2

Related Questions