2011-08-28 7 views
0

내 페이스 북 응용 프로그램이 초기에 사용자의 기본 권한을 묻는 중이었습니다. 이제 확장 된 권한을 필요로하는 몇 가지 기능을 추가 했으므로 다음과 같이 코드를 변경하고 제거한 다음, 응용 프로그램을 추가하면 응용 프로그램의 다른 내용을 변경해야합니다.Facebook 응용 프로그램이 기본 대신 확장 된 권한을 요청했습니다.

내가 프로필에서 응용 프로그램을 제거하고 다시 추가하려고하면 기본 정보를 묻는 메시지가 나타납니다.이 경고가 표시 될 때 확장 된 권한이 필요하다고 페이스 북에 어떻게 알릴 수 있습니까? OAuthException : (# 200) 사용자가이 작업을 수행하도록 응용 프로그램을 허가하지 않았습니다.

변경 사항의 앱 비법을 재설정해야합니까?

> $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>'); 
> } 

답변

1

아래의 코드가 작동하는지 확인하려면 먼저 권한을 확인한 다음 스트림을 게시하고 권한이 없으면 사용자에게 권한을 요청하십시오.

$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"))); 
      } 
1

최신 3.0 PHP SDK를 사용하는 경우 getLoginUrl을 호출 할 때 req_perms를 범위로 변경하십시오. 이것은 새로운 PHP SDK 버전에서 변경되었습니다.

또한 사용자가 앱에 필요한 확장 권한을 부여 받았는지 확인하고 필요하지 않은 경우 권한을 다시 요청해야합니다. 예를 들어 FacebookApiException을 catch 한 다음 getLoginUrl()으로 리디렉션하지만 해당 로그인은 코드에서 이전처럼 필요한 범위를 지정해야합니다.

+0

제안에 감사하지만 예외는 여전히 – PUG

+0

는 – PUG

+2

업데이트를 만든 변화가했다. 마지막에는 api 예외 (일명 권한 없음)가있는 경우 두 번째 getLoginUrl을가집니다. 해당 호출에 필요한 범위도 추가하십시오. – bkaid

관련 문제