English 中文(简体)
How to test the twitter API locally?
原标题:

I m trying to write a web application that would use Twitter via OAuth.

  1. I run my local server as localhost , so I need the callback URL to be something like http://localhost/something/twitter.do but Twitter doesn t like that: Not a valid URL format

  2. I m probably going to do a lot of tests, but once I ve approved my app with my username, I can t test again can I? Am I supposed to create multiple twitter accounts? Or can you remove an app and do it again?

问题回答
  1. You can use 127.0.0.1 instead of localhost.

  2. You can authorize your app as many times as you like from the same twitter account without the necessity to revoke it. However, the authenticate action will only prompt for Allow/Deny once and all subsequent authenticate requests will just pass through until you revoke the privilege.

Twitter s "rate limiting" for API GET calls is based on IP address of the caller. So, you can test your app from your server, using the same IP address, and get (once approved) 15,000 API calls per hour. That means you can pound on your app with many different usernames, as long as your approved IP address remains the same.

When you send the e-mail to Twitter to ask for an increase to your rate limit, you can also ask for the increase to apply to your Twitter username too.

I believe Twitter requires you - if you need to change your IP address, or change the username that is using the app - to send in another request asking for the rate limit increase for that new IP address or username. But, in my experience, Twitter has been pretty quick at turning around these requests (maybe less than 48 hours?).

use like this for Website :http://127.0.0.1 and for callback URL: http://127.0.0.1/home or any of your page address like http://127.0.0.1/index

Have you tried creating your own caching mechanism? You can take the result of an initial query, cache it on thread local, and given an expiration time, refresh from Twitter. This would allow you to test your app against Twitter data without incurring call penalties.

There is also another solution (a workaround, rather) which requires you to edit your hosts file.

Here is how you do it on a linux box:

  1. Open your /etc/hosts file as root. To do this, you can open a terminal and type something like sudo vi /etc/hosts.

  2. Pick a non-existent domain to use as your local address, and add it to your hosts file. For example, you will need to add something similar to the following at the end.

    127.0.0.1 localhost.cep # this domain name was accepted.
    

So, that s pretty much it. Pointing your browser to localhost.cep will now take you to your local server. Hope that helped :)

In answer to (1), see this thread, in particular episod s replies: https://dev.twitter.com/discussions/5749

It doesn t matter what callback URL you put in your app s management page on dev.twitter.com (as long as you don t use localhost). You provide the real callback URL as part of your request for an OAuth token.





相关问题
Understanding Twitter API s "Cursor" parameter

I don t really get how to use the Curesor parameter in Twitter s API, for an exmaple - here. Am I supposed to make a new API call for each 100 followers? I d love it if someone could provide a PHP ...

Cannot get Twitter-OAuth-iPhone to work

demo works as expected, no problems. But now I m trying to integrate it into my project. I use no xib-s, code only: OAuthTwitterDemoViewController *vc = [[OAuthTwitterDemoViewController alloc] init]; ...

Creating a constantly updating feed like Twitter

I d like to have something in my app that is just like Twitter but not Twitter. Basically it will be a place people can submit messages and do not need an account. They only way they can submit is ...

RegEx: Link Twitter-Name Mentions to Twitter in HTML

I want to do THIS, just a little bit more complicated: Lets say, I have an HTML input: <a href="http://www.example.com" title="Bla @test blubb">Don t break!</a> Some Twitter Users: @...

twitter status update using tweetsharp oauth preview 17

I am trying to update the status using tweetsharp oauth preview 17. Please let me know how ?. I tried this code var msg = FluentTwitter.CreateRequest() .AuthenticateWith(_consumerKey, ...

How to test the twitter API locally?

I m trying to write a web application that would use Twitter via OAuth. I run my local server as localhost , so I need the callback URL to be something like http://localhost/something/twitter.do ...

Get follower count on Twitter API search results

What I m trying to do is pull some search results, and sort them by users. Right now I m using $to->OAuthRequest( http://search.twitter.com/search.json , array( q => search-term ), GET ); to ...

热门标签