0

作为我登录过程的一部分,我正在尝试检查用户是否已接受所需的权限。我编写了一个函数来检索他们接受的权限并返回它们是否正确。如果这返回 false 我想构建 loginUrl 以将它们定向到身份验证对话框,以便他们可以接受额外的权限。

// Declares the required permissions
        $reqPerms = array(
            'user_status',
            'user_videos'
        );

        $permVer = verifyPermissions($reqPerms);

        if (!$permVer) {
            //$s = "'scope' => '" . implode("','", $reqPerms) . "' ";
            $s = "'".implode("','", $reqPerms)."'";

            echo $s." ";
            $loginUrl = $facebook->getLoginUrl(array(
                'scope' => $s,
                'redirect_uri' => $fbconfig['appUrl']
                ));
print "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";

这会导致以下错误:

API Error Code: 100
    API Error Description: Invalid parameter
    Error Message: Unsupported scope: ''user_status''. 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

如果我在方法中明确引用权限“user_status”和“user_videos”,我决定在$loginUrl自动生成的 $loginUrl 旁边回显我正在构建的内容getLoginUrl()

登录 url 的范围部分不同,这显然与 url 编码有关:

构造的 URL: scope=%27user_status%27%2C%27user_videos%27 生成的 URL: scope=user_status&0=user_status&1=user_videos

如果我只是将$reqPerms直接传递给getLoginUrl我得到的函数: scope=user_status%2Cuser_videos

我的问题是:如何编辑我的代码以使 URL 的“范围”部分正确显示?

4

1 回答 1

1

主要的问题在于你的

        $loginUrl = $facebook->getLoginUrl(array(
        'scope' => $s,
        'redirect_uri' => $fbconfig['appUrl']
        ));

你可以参考

正确的应该是:

$login_url = $facebook->getLoginUrl( array( 
'scope' => 'user_status, user_videos'
) );
于 2012-08-15T10:58:39.157 回答