문제

Trying to upload a photo rendered on my server to the facebook album of the user on the fly. Since FB Docs are very,very,very bad (to say the least) I was hoping for someone to show me some good code examples of Graph API calls with the PHP SDK?

도움이 되었습니까?

해결책

Something like this.

     try {
        $facebook->setFileUploadSupport('http://www.example.com/');
        $response = $facebook->api(
          '/me/photos/',
          'post',
          array(
            'message' => 'This is my image caption',
            'source' => '@/path/to/image' // @-sign must be the first character
          )
        );
      }
      catch (FacebookApiException $e) {
        error_log('Could not post image to Facebook.');
      }

EDIT: First you need to authenticate, by using this code.

$facebook = new Facebook(array(
  'appId'  => 'YOUR_APP_ID',
  'secret' => 'YOUR_APP_SECRET',
  'cookie' => TRUE,
  'domain' => $_SERVER['SERVER_NAME']
));

$facebook->getSession();

try {
  $me = $facebook->api('/me');
}
catch (FacebookApiException $e) {
  $me = NULL;
}

if ( is_null($me) ) {
  $auth_url = $facebook->getLoginUrl(array(
    'req_perms' => 'read_stream,publish_stream,user_photos'
  ));

  header("Location: $auth_url");
}

Here is a link to all permissions you can ask the user for.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top