0

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

我实际上是在尝试让自定义 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 Login froma FB Login 按钮有效,但我需要它来完成此流程,以便“无摩擦”行为运行(即,我不能点击另一个按钮)

4

1 回答 1

1

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

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

于 2012-06-24T16:36:47.777 回答