Twitter OAuth

新浪微博和 Twitter 的 Oauth API 为什么感觉流程不一样

新浪:

  1. 开发者引导用户到新浪授权页面, 页面链接中需要带上自己的 apikey :
  2. 用户授权后新浪跳转到开发者指定指定的页面,并且附上服务器返回的一枚 code 作为 param ;
  3. 开发者用这枚 code ,再加上自己的 apikey 和 api secret 去 post https://api.weibo.com/oauth2/access_token ;
  4. post 返回 access_token;
  5. 以后开发者每次用这枚 access_token 请求用户资源。

Twitter:

  1. 开发者首先把自己的 apikey 等信息加密作为 Header 里面的 Authorization 去 post https://api.twitter.com/oauth/request_token?call_back=balabala , 获得 auth_token ;
  2. 开发者再把用户引导到 Twitter 授权页面,并且需要传入这枚 auth_token 作为参数;
  3. 用户授权后开发者再获得 oauth_token 和 oauth_verifier , 开发者再把这一步获得的 auth_token 和 第一步的进行校验;
  4. 开发者再拿上一步获得的 oauth_verifier 和 oauth_token 去 post https://api.twitter.com/oauth/access_token , 成功后获得 oauth_token, uid, username 这些,然后再自己解析获得 access_token 。
  5. 以后开发者每次用这枚 access_token 请求用户资源。

感觉 Twitter 的要麻烦, 主要就是在引导用户授权之前还要自己先去 post 服务器临时获得一枚 auth_token 。

官网Twitter OAuth

Twitter API开发与OAuth介绍

Question: How long does an access token last?

Answer: We do not currently expire access tokens. Your access token will be invalid if a user explicitly rejects your application from their settings or if a Twitter admin suspends your application. If your application is suspended there will be a note on your application page saying that it has been suspended.

Obtaining Ads Account Access

Single-user OAuth with Examples

Access Tokens

OAuth Trick in coding

Twitter libraries

API reference index

Securing keys and access tokens

 

 

原文地址:https://www.cnblogs.com/panpanwelcome/p/9800438.html