Authentication for twitter API and Rest Call

℡╲_俬逩灬. 提交于 2019-12-04 06:18:50

You can use this javascript library: codebird-js with the "Application-only auth".

or

Do it yourself: everything is explained in the documentation.

Basically you need to follow 3 steps (and you should do the 2 first just once):

  • An application encodes its consumer key and secret into a specially encoded set of credentials.
  • An application makes a request to the POST oauth2/token endpoint to exchange these credentials for a bearer token.
  • When accessing the REST API, the application uses the bearer token to authenticate.

The steps are detailed in the documentation.

You can do the first 2 separately and when you get your bearer token, you need to add a specific HTTP Header (Authorization) in each request with your bearer token (that's the 3rd step). With jQuery it could be something like that:

$.ajax({
  headers: { Authorization: 'Bearer '+$my_bearer_token },
  url: 'https://api.twitter.com/1.1/search/tweets.json?q='+$search
}).done(function (data) {
  // Play with the data
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!