Authenticate API Calls for trends/place


#1

My main question that I posted is on Stackoverflow, but I haven’t gotten any answers!

I am working on a website that allows the user to search for the top ten twitter trends in a city or country. At first I was only relying on Twitter’s Rest API, but I was having a lot of rate limit issues (at school my rate limit disappears faster than I have a chance to use it). I know that authenticating my API calls will help me to better deal with this issue (Authenticated API calls are charged to the authenticating user’s limit while unauthenticated API calls are deducted from the calling IP address’ allotment).

I implemented @abraham’s PHP library (https://github.com/abraham/twitteroauth), unfortunately my API calls aren’t being authenticated. I know I have implemented @abraham’s PHP library, because it prints out my user information at the end like it should. I have my twitter trend search underneath it isn’t being authenticated.

In Abraham’s php example there are the following calls:

/* Some example calls */
//$connection->post(‘statuses/update’, array(‘status’ => date(DATE_RFC822)));
//$connection->post(‘statuses/destroy’, array(‘id’ => 5437877770));
//$connection->post(‘friendships/create’, array(‘id’ => 9436992));
//$connection->post(‘friendships/destroy’, array(‘id’ => 9436992));

I recently added this one (below) to my code, but it still isn’t working:

$connection->get(‘trends/place’, array(‘id’ => $woeid));

I am not sure how to fix this, and any help would really be appreciated!


#2

If you’re using API v1, keep in mind that many methods that support but do not require authentication will give you a “free pass” when bad authentication data is presented and will serve you a response regardless. API v1.1 is less forgiving.

I wouldn’t necessarily think just because you have data returning in the app in some contexts that your OAuth is correctly functioning. Be sure and verify your timestamp is correct and that you’re using the library correctly – it’s unclear which version of the API you’re using from these small code examples.


#3

We’re experiencing the same thing. We’re using @abraham’s PHP libraries. We’ve switched all our calls to the 1.1 API and authentication via this library is working there (statuses/home_timeline, statuses/user_timeline, statuses/show, favorites/list, search/tweets). The library is attempting a GET on this URL:
https://api.twitter.com/1.1/trends/place.json?id=2450022&oauth_consumer_key=SWD0LerZcjFWTm9defmStg&oauth_nonce=50859877fe5d9ab3304c9acd60bf41be&oauth_signature=4SyNnK5ijgfKrTDupIt9LL1mdPA%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1351010019&oauth_version=1.0

I tried using the OAuth Tool on the dev.twitter.com site and (quickly) plugging the values it returns into the above URL, but that failed too.


#4

You’re not presenting an oauth_token in that request belonging to a user account – at this time, you’ll need to provide a user context for a request like that to work.

I was able to request this method without issue when using all the aspects of OAuth necessary to perform the request:

GET https://api.twitter.com/1.1/trends/place.json?id=2450022

Signature base string:
GET&https%3A%2F%2Fapi.twitter.com%2F1.1%2Ftrends%2Fplace.json&id%3D2450022%26oauth_consumer_key%3D5aA6oofBOFAwN4tfmEYWjg%26oauth_nonce%3Dl7OtaK83Rlv4tQML84ZFydVO2fM3yTCcuBrq6Xh0UAY%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1351010709%26oauth_token%3D119476949-oYGCs2M5duG5QalbOAK2YUZh8zG3ur7DPYo5qIFN%26oauth_version%3D1.0

Auth header:
OAuth oauth_nonce=“l7OtaK83Rlv4tQML84ZFydVO2fM3yTCcuBrq6Xh0UAY”, oauth_signature_method=“HMAC-SHA1”, oauth_timestamp=“1351010709”, oauth_consumer_key=“5aA6oofBOFAwN4tfmEYWjg”, oauth_token=“119476949-oYGCs2M5duG5QalbOAK2YUZh8zG3ur7DPYo5qIFN”, oauth_signature=“v55eC9NJoASgRraUFp2kQZfF2A4%3D”, oauth_version=“1.0”


#5

Right you are @episod. Thank you much, my wiring was not complete. Now that I’ve got the oauth_token included this is working for me.


#6

Thank you for this information! I think this is one of the issues that I need to fix.