PHP - 上传通过图形API的web托管照片Facebook相册 [英] PHP - Upload a web hosted photo to facebook album via Graph API

查看:206
本文介绍了PHP - 上传通过图形API的web托管照片Facebook相册的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想上传托管WWW(如的http:// www.google.se/intl/en_com/images/srpr/logo1w.png )文件到Facebook相册。

I'm trying to upload www hosted (e.g. http://www.google.se/intl/en_com/images/srpr/logo1w.png) files to a facebook album.

创建相册工作得很好,但我好像没有上传任何照片做。我使用Facebook的PHP-SDK( http://github.com/facebook/php-sdk/ ),我已经尝试过的例子是:

Creating an album works just fine, but I don't seem to uploading any photos. I'm using the facebook php-sdk ( http://github.com/facebook/php-sdk/ ) and the examples I already tried are:

<一个href=\"http://stackoverflow.com/questions/2718610/upload-photo-to-album/2728275#2728275\">http://stackoverflow.com/questions/2718610/upload-photo-to-album/2728275#2728275

<一个href=\"http://stackoverflow.com/questions/2964410/how-can-i-upload-photos-to-album-using-facebook-graph-api/3006901#3006901\">http://stackoverflow.com/questions/2964410/how-can-i-upload-photos-to-album-using-facebook-graph-api/3006901#3006901

我猜卷曲上传也许只能管理本地存储的文件,而不是网络托管的。

I'm guessing CURL uploads perhaps only can manage locally stored files and not web hosted ones.

下面是我的code:

      /*
  Try 1:

  $data = array();
  $data['message'] = $attachment->post_title;
  $data['file'] = $attachment->guid;

  try {
   $photo = $facebook->api('/' . $album['id'] . '/photos?access_token=' . $session['access_token'], 'post', $data);
  } catch (FacebookApiException $e) {
   error_log($e);
  }
  */

  // Try 2:
  //upload photo
  $file = $attachment->guid;
  $args = array(
   'message' => 'Photo from application',
  );
  $args[basename($file)] = '@' . realpath(file_get_contents($file));

  $ch = curl_init();
  $url = 'https://graph.facebook.com/' . $album['id'] . '/photos?access_token=' . $session['access_token'];
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HEADER, false);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
  $data = curl_exec($ch);
  //returns the photo id
  print_r(json_decode($data,true));

...其中attachment-> GUID包含照片的URL。

...where attachment->guid contains the photo url.

我是pretty多卡现在...

I'm pretty much stuck right now...

推荐答案

我认为这个问题是在这里:

i think the problem is here:

$args[basename($file)] = '@' . realpath(file_get_contents($file));

因为你要发布来自其他来源的照片(右),你应该暂时保存在您自己的主机上。

since you want to post a picture from another source (right?), you should save it temporarily on your own host.

我也需要做这样的事情,因为我不得不处理图像,我用下面的方法:

i also needed to do something like this, and since i had to process the image, i used the following way:

$im = @imagecreatefrompng('http://www.google.se/intl/en_com/images/srpr/logo1w.png');
imagejpeg($im, 'imgs/temp/temp.jpg', 85);

$args['image'] = '@' . realpath('imgs/temp/temp.jpg');

剩下的看起来很好,虽然

the rest looks fine though

这篇关于PHP - 上传通过图形API的web托管照片Facebook相册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆