4

当您成功用“代码”交换令牌时

facebook回复以下内容(html正文)

 access_token=USER_ACCESS_TOKEN&expires=NUMBER_OF_SECONDS_UNTIL_TOKEN_EXPIRES

但是当这个代币交换代码失败时会发生什么?交换失败时facebook如何响应?

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

4

1 回答 1

15

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

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

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

从 facebook 请求访问令牌时客户端密码错误,返回 json 错误:

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

从 facebook 请求访问令牌时出现错误代码,返回 json 错误:

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

从 facebook 请求访问令牌时授予类型错误,返回 json 错误:

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

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

{
   "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
   }
}

当然,当我不附加123abc到值时,在每种情况下都会正确返回访问令牌。

这些回复截至 2012 年 12 月,但当然 facebook 可能会决定在未来的任何时候更改它们而不会发出警告。

于 2013-01-31T00:11:36.520 回答