开发者

Facebook application now asking for extended permission instead of basic,

开发者 https://www.devze.com 2023-04-01 10:05 出处:网络
My facebook application was initially asking for basic permission from user, now i have added some feature which require extended permisssion, beside changing the code to as follows and removing and t

My facebook application was initially asking for basic permission from user, now i have added some feature which require extended permisssion, beside changing the code to as follows and removing and the re-adding the application do i need to change anything else for the application.

Coz when i removed the app from my profile and then tried to re add it, it only asked for Basic information, how do i tell facebook that this app need extended permission now as it is giving me this warning: OAuthException: (#200) The user hasn't authorized the application to perform this action.

Do i need to reset the app secret of change some setting there?

> $facebook = new Facebook(array(   'appId'  => 'xxxxxxxxxxxx',  
> 'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx', ));
> 
> // Get User ID
> 
> 
> $user = $facebook->getUser(); if ($user) {   try {
>     // Get the user profile data you have permission to view
>     $user_profile = $facebook->api('/me');
>     $uid = $facebook->getUser();
>      
>     
>       $url = $facebook->getLoginUrl(array(
>     'canvas' => 1,
>     'fbconnect' => 0,
>     'scope' =>'publish_stream'));
>     
>     
>     $attachment = array  ( 
> 'access_token'=>$facebook->getAccessToken(),  'message' => 'I had a
> question: should I write a PHP facebook app that actually worked?', 
> 'name' => 'I Asked Bert',  'caption' => 'Bert replied:',  'link' =>
> 'http://apps.facebook.com/askbert/',  'description' => 'NO', 
> 'picture' => 'http://www.facebookanswers.co.uk/img/misc/question.jpg' 
> );  echo "Test 1"; 
> 
> $result = $facebook->api('/me/feed/','post',$attachment);
>  
>     echo "Test 2"; 
>     $_SESSION['userID'] = $uid;
> 
> 
>   } catch (FacebookApiException $e) {
>     $user = null;   } } else {   die('Somethign Strange just happened
> <script>top.location.href="'.$facebook->getLoginUrl(开发者_运维技巧).'";</script>');
> }


If you are using the newer 3.0 PHP SDK, then change req_perms to scope when calling getLoginUrl. This changed in the newer PHP SDK version.

Also, you will want to verify that the user still has granted your app the extended permissions needed, and if they haven't, re-prompt them for permissions. For example, you catch a FacebookApiException and then redirect them to the getLoginUrl() but that login should also specify the scopes needed like you do earlier in your code.


below code is working, the thing was to check for permission first then publish stream and if no permission found then ask user for permission.

$facebook = new Facebook(array(
  'appId'  => 'xxxxxxxxxxxxxxxxxx',
  'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
));
$user = $facebook->getUser();
$user_profile = $facebook->api('/me');


if( array_key_exists('publish_stream', $permissions['data'][0]) ) {
                // Permission is granted!
                // Do the related task
                //$post_id = $facebook->api('/me/feed', 'post', array('message'=>'Hello World!'));
                  $post_id = $facebook->api('/me/feed', 'post', $attachment);

            } else {
                // We don't have the permission
                // Alert the user or ask for the permission!
                echo "Click Below to Enter!";
                header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream")) );
            }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号