Facebook上传照片 [英] facebook upload photo

查看:275
本文介绍了Facebook上传照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Facebook的新朋友,我有一个小问题。
我正在尝试将图片上传到用户的相册。为此,我使用了一个PHP脚本,我发现这里,堆栈溢出:

I'm new to the facebook api, and i have a small issue. I'm trying to upload a picture to an album of an user. For this i'm using a PHP script i've found here, on stack overflow :

    $app_id = xxx;
$app_secret = "xxx";
$my_url = "http://apps.facebook.com/myapp/test.php";

$code = $_REQUEST["code"];

if(empty($code)) {
    $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" 
        . $app_id . "&redirect_uri=" . urlencode($my_url);

    echo("<script> top.location.href='" . $dialog_url . "'</script>");
}


$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
    . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret="
    . $app_secret . "&code=" . $code;

$access_token = file_get_contents($token_url);

//upload photo
$file= 'test.png';
$args = array(
   'message' => 'Photo from application',
);
$args[basename($file)] = '@' . realpath($file);

print_r($args);

$ch = curl_init();
$url = 'https://graph.facebook.com/2038278/photos?access_token='.$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));

但结果是:


Array([message] =>照片来自
应用程序[test.png] =>
@ / [mypath] /test.png)Array([error]
=> Array([type] => OAuthException [message] =>验证
应用程序时出错))

Array ( [message] => Photo from application [test.png] => @/[mypath]/test.png ) Array ( [error] => Array ( [type] => OAuthException [message] => Error validating application. ) )

这个意思 ?我需要对我的应用程序拥有扩展权限吗?
i给了它基本和user_photos

What does this mean ? Do i need to have extended permissions for my app ?wich of them ? i gave it acces to basic and user_photos

非常感谢!

第二个脚本

$ app_id =xxx;
$ app_secret =xxx;
$ my_url =http://apps.facebook.com/myapp/test.php;

$app_id = "xxx"; $app_secret = "xxx"; $my_url = "http://apps.facebook.com/myapp/test.php";

$code = $_REQUEST["code"];

if(empty($code)) {
    $dialog_url = "http://www.facebook.com/dialog/oauth?client_id=" 
        . $app_id . "&redirect_uri=" . urlencode($my_url) . "&scope=user_photos" ;

    echo("<script> top.location.href='" . $dialog_url . "'</script>");
}


$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
    . $app_id . "&redirect_uri=" . urlencode($my_url) . "&client_secret="
    . $app_secret . "&code=" . $code;

$access_token = file_get_contents($token_url);









$token = $access_token;

//upload photo
$file= 'test.png';
$args = array(
'message' => 'Photo from application',
);
$args[basename($file)] = '@' . realpath($file);

$ch = curl_init();
$url = 'https://graph.facebook.com/me/photos?access_token='.$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);

print_r(json_decode($data,true));


推荐答案

我想你需要你的申请要求许可称为 publish_stream 。还有另一个许可称为 photo_upload ,但据了解,这被认为是旧的(但仍可以工作)

I think you need your application to ask for the permission called publish_stream. There is also another permission called photo_upload, but as I understand that is considered old (but may still work)

这篇关于Facebook上传照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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