Constructing own loginUrl with correct URL encoding
As part of my login procedure I'm trying to check that the user has accepted the required permissions. I have written a function to retrieve the permissions they've accepted and return whether they are correct. If this returns false I want to construct the loginUrl to direct them to the auth dialog so that they can accept the additional permissions.
This results in the following error below:
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
I decided to echo out the $loginUrl which I was constructing next to the $loginUrl which is generated automatically if I explicitly reference the permissions 'user_status' and 'user_videos' in the getLoginUrl() method.
The scope part of the login url is different, and this apparently has to do with url encoding:
Constructed URL: scope=%27user_status%27%2C%27user_videos%27 Generated URL: scope=user_status&0=user_status&1=user_videos
If I just pass the $reqPerms straight into the getLoginUrl function I get: scope=user_status%2Cuser_videos
My question is: how can edit my code so that the 'scope' part of the URL appears properly?
The mostly problem is in your
$loginUrl = $facebook->getLoginUrl(array( 'scope' => $s, 'redirect_uri' => $fbconfig['appUrl'] ));
The right thing should be:
$login_url = $facebook->getLoginUrl( array( 'scope' => 'user_status, user_videos' ) );