Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/234.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Facebook PHP SDK上载图像-图像路径_Php_Facebook_Facebook Php Sdk - Fatal编程技术网

Facebook PHP SDK上载图像-图像路径

Facebook PHP SDK上载图像-图像路径,php,facebook,facebook-php-sdk,Php,Facebook,Facebook Php Sdk,在网站上提供在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',

在网站上提供在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授权应用程序,显示错误消息的最佳方式是什么。
或者像致命错误这样的错误:未捕获的OAutheException发生

我在我的应用程序中也做了同样的事情,jst来处理这个。。 确保您具有发布\u流的权限

$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

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

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

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