【问题标题】:Cannot get FB.ui Method:oauth to work无法获得 FB.ui 方法:oauth 工作
【发布时间】:2012-06-23 14:11:55
【问题描述】:

我整个上午都在和这个作斗争。

我实际上是在尝试让自定义 Open Graph Actions 起作用。我已经成功了,将来自各处的信息拼凑在一起,现在我有一个按钮,可以通过以下流程发布“想要”操作:

> User Clicks Button
> FB.api checks response.
    > if response code is 200 the user has not granted publish_stream permission
        > call FB.ui({ method:
                  "permissions.request",
                  "perms": 'email,publish_stream'
                }
        > call back to original function and post to stream
    > if user has already granted permission, then just publish

一切都很好。

不过,我需要的是捕捉用户根本没有登录 Facebook 的情况。

这似乎是响应代码 2500,其中不存在访问令牌

所以我有这段代码片段,它可以捕捉到这种情况

.....
} else if (((response.error.code) * 1) == 2500) {
    doLogin('publish_stream', postWant, itemId); 
    // post want being the original function and itemId being the item we are "wanting"
}

我的 doLogin 函数如下所示:

    function doLogin(permRequired, callingFunction, urlAppend) {
        FB.ui({ 
            method: 'oauth', 
            scope: 'email,' + permRequired
        },
        function (response) {
            // DO THINGS NOW WE'RE LOGGED IN
        });
    };

这和我获取扩展权限的函数基本一模一样,看起来是这样的:

    function getPermission(permRequired, callingFunction, urlAppend) {
        FB.ui({ method:
            "permissions.request",
            "perms": 'email,' + permRequired
        },
        function (response) {
            // DO THINGS NOW WE HAVE PERMISSION
        });
    };

后一个示例可行,但登录示例只是加载一个弹出窗口,上面写着“抱歉,出了点问题,请稍后再试”

显然已经调用了 FB.init,APP 设置正确,在 FB.init 中声明了 APP_ID 等等,显然,就像其他东西一样。

从 FB 登录按钮进行 FB 登录有效,但我需要它来完成此流程,以便“无摩擦”行为能够运行(即,我不能点击另一个按钮)

【问题讨论】:

    标签: facebook facebook-javascript-sdk facebook-opengraph facebook-oauth fb.ui


    【解决方案1】:

    不要将 FB.ui 与 method:"permissions.request" 一起使用 - 只需使用 FB.login,并将 options 参数设置为您需要的(附加)权限范围。

    https://developers.facebook.com/docs/reference/javascript/FB.login/

    【讨论】:

      猜你喜欢
      • 2014-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-26
      • 2016-01-02
      • 2012-06-14
      • 2023-03-12
      • 2022-07-07
      相关资源
      最近更新 更多