Facebook交换代码用于令牌 [英] Facebook exchange code for token

查看:273
本文介绍了Facebook交换代码用于令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您成功交换令牌的代码

When you successfully exchange a "code" for a token

Facebook回复与以下(html正文)

facebook responses with the following (html body)

 access_token=USER_ACCESS_TOKEN&expires=NUMBER_OF_SECONDS_UNTIL_TOKEN_EXPIRES

但是什么当代码令牌交换失败时,会发生什么?当交换失败时,Facebook如何回应?

But what happens when this code for token exchange fails? how does facebook response when the exchange fails?

参考 https://developers.facebook.com/docs/howtos/login/server-side-login/

推荐答案

当请求中的某个参数不正确时,Facebook无法将访问令牌返回给您的应用程序。在我的oauth框架的开发期间,我测试了将每个必需参数设置为不正确的值(即,将字符串 123abc 添加到正确值的开头)。以下是结果:

facebook can fail to return an access token to your application whenever one of the parameters in the request is incorrect. during development of my oauth framework i tested setting each required parameter to an incorrect value (ie i appended the string 123abc to the start of the correct value). here are the results:

从Facebook上请求访问令牌时,错误的客户端ID,返回json错误:

wrong client id when requesting the access token from facebook, returns json error:

{
   "error": {
      "message": "Error validating application. Invalid application ID.",
      "type": "OAuthException",
      "code": 101
   }
}

错误的客户端请求来自Facebook的访问令牌的秘密,返回json错误:

wrong client secret when requesting the access token from facebook, returns json error:

{
   "error": {
      "message": "Error validating client secret.",
      "type": "OAuthException",
      "code": 1
   }
}

从Facebook上请求访问令牌时错误代码,返回json错误:

wrong code when requesting the access token from facebook, returns json error:

{
   "error": {
      "message": "Invalid verification code format.",
      "type": "OAuthException",
      "code": 100
   }
}

错误的授权类型当请求ac来自Facebook的cess令牌,返回json错误:

wrong grant type when requesting the access token from facebook, returns json error:

{
   "error": {
      "message": "Invalid grant_type: '123abcauthorization_code'. Supported types: authorization_code, client_credentials",
      "type": "OAuthException",
      "code": 100
   }
}

从Facebook上请求访问令牌时错误的范围,返回json错误:

wrong scope when requesting the access token from facebook, returns json error:

{
   "error": {
      "message": "Unsupported scope: '123abcemail'. Supported scopes: ads_management create_event create_note email export_stream friends_about_me friends_activities friends_birthday friends_checkins friends_education_history friends_events friends_games_activity friends_groups friends_hometown friends_interests friends_likes friends_location friends_notes friends_online_presence friends_photo_video_tags friends_photos friends_questions friends_relationship_details friends_relationships friends_religion_politics friends_status friends_subscriptions friends_videos friends_website friends_work_history manage_friendlists manage_notifications manage_pages offline_access photo_upload publish_actions publish_checkins publish_stream read_friendlists read_insights read_mailbox read_page_mailboxes read_requests read_stream rsvp_event share_item sms status_update user_about_me user_activities user_birthday user_checkins user_education_history user_events user_games_activity user_groups user_hometown user_interests user_likes user_location user_notes user_online_presence user_photo_video_tags user_photos user_questions user_relationship_details user_relationships user_religion_politics user_status user_subscriptions user_videos user_website user_work_history video_upload xmpp_login",
      "type": "OAuthException",
      "code": 100
   }
}

这些值在每种情况下均可正确返回。

and of course when i do not append 123abc to the values then the access token is returned correctly in each case.

这些回复是截至2012年12月,但是当然Facebook可能会决定在未来没有警告。

these responses are as of december 2012, but of course facebook may decide to change them at any point in the future without warning.

这篇关于Facebook交换代码用于令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆