【问题标题】:Facebook PHP SDK Upload Images - Path of ImageFacebook PHP SDK 上传图片 - 图片路径
【发布时间】:2013-03-30 04:59:23
【问题描述】:

在网站上提供选项以在 facebook 上单击和上传图像: 搜索后得到此代码

$pic = $_GET['PhotoID']; //example: http//www.mysite.com/content/2013/03/image.jpg
copy($pic, 'tmp/file.jpg');
$args['image'] = '@' . realpath('tmp/file.jpg');
$publish = $facebook->api('/me/photos', 'post', $args);
unlink('tmp/file.jpg');

此代码运行良好。 但是将图像复制到 tmp 需要一些时间,我想加快这个过程。 (仅从我的网站上传图片,没有外部图片)

如何在不复制到 temp 的情况下使用此代码:

 $pic = $_GET['PhotoID']; //example: http://www.mysite.com/content/2013/03/image.jpg
    $args['image'] = '@' . realpath('$pic');
    $publish = $facebook->api('/me/photos', 'post', $args);

不确定 '@' 和 realpath 的用法 我可以在不使用 realpath 的情况下使用完整的图像 url:

`$args['image'] = $pic;
        $publish = $facebook->api('/me/photos', 'post', $args);`

& 如果用户 dnt 授权应用程序,显示错误消息的最佳方式是什么。 或致命错误:发生未捕获的 OAuthException 之类的错误

【问题讨论】:

  • @AdvaitAmin 抱歉,它与问题无关。我想要带有图像绝对路径的示例代码(图像的完整 url)
  • 您的问题是将图像复制到 tmp 需要一些时间您想加快该过程意味着上传过程需要太多时间...
  • 是的,我想在 $publish 中直接使用图片 url($pic) 而不是 tmp 文件复制过程
  • 检查我在上面给出的链接的编辑答案。

标签: php facebook facebook-php-sdk


【解决方案1】:

您不需要将图像复制到/tmp。您可以通过在参数中提供图片网址本身来直接上传图片。下面的代码应该可以工作:

$picUrl = 'http//www.mysite.com/content/2013/03/image.jpg';
$photoId = $facebook->api("me/photos","POST",array('url'=>$picUrl,'message'=>"status message")

【讨论】:

    【解决方案2】:

    我在我的应用程序中做了同样的事情,请继续使用这个.. 确保您拥有 publish_stream 权限

    $attachment = array(
                    'message' => 'Message',
                    'name' =>'your app name',
                    'caption' => "caption under the image",
                    'link' => 'your link',
                    'description' => 'description regarding the image',
                    'picture' => 'path of the picture(doesnt work for the local path, should be server path)',
                    'method'=>'stream.publish',
                    'actions' => array(
                                    array(
                                      'name' => 'App name',
                                      'link' => 'your app link'
                                    )
                                )
                    );
    

    之后

    $result = $facebook->api('/'.$uid.'/feed/','post',$attachment);
    

    这里的 $uid 是您的 facebook 用户 ID,您可以从 facebook 配置文件中获取它

    $facebook = new Facebook('configure your facebook config file here');    
    $my_details = $facebook->api('/me');
    $uid = $my_details['id'];  // id of the user
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-11
      • 2012-01-25
      • 1970-01-01
      • 2017-07-27
      • 2012-04-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多