Facebook 如何将照片上传到粉丝的个人资料中,并附上他们的名字?
喜欢这个应用吗 帮助我…为您提供的示例代码Facebook 如何将照片上传到粉丝的个人资料中,并附上他们的名字?,facebook,upload,Facebook,Upload,喜欢这个应用吗 帮助我…为您提供的示例代码 <?php // Remember to copy files from the SDK's src/ directory to a // directory in your application on the server, such as php-sdk/ require_once('src/facebook.php'); $config=array();
<?php
// Remember to copy files from the SDK's src/ directory to a
// directory in your application on the server, such as php-sdk/
require_once('src/facebook.php');
$config=array();
$config['appid']='****';
$config['secret']='*********';
$config['appurl']='http://apps.facebook.com/YOUR APP/';
$configsdk = array(
'appId' => $config['appid'],
'secret' => $config['secret'],
'fileUpload' => TRUE, // optional
);
$facebook = new Facebook($configsdk);
$user_id = $facebook->getUser();
if(empty($user_id)){
$dialog_url = "https://www.facebook.com/dialog/oauth?client_id="
. $GLOBALS['config']['appid'] . "&redirect_uri=" . urlencode($config['appurl']).'&scope=publish_stream';
echo ("<script> top.location.href='".$dialog_url ."' </script>");
break;
}
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
$user=$facebook->api('me','GET');
} catch(FacebookApiException $e) {
error_log($e->getType());
error_log($e->getMessage());
}
$src['0']='http://techsinter.com/apps/picbackg.jpg';
$iTmp2 = imagecreatefromjpeg($src['0']);
$iOut = imagecreatetruecolor ("740","680") ;
@imagecopy ($iOut,$iTmp2,0,0,0,0,imagesx($iTmp2),imagesy($iTmp2));
@imagedestroy ($iTmp2);
$white = imagecolorallocate($iOut, 0xFF, 0xFF, 0xFF);
// Path to our ttf font file
$font_file = './arial.ttf';
// Draw the text 'PHP Manual' using font size 13
$photo=time().'.png';
imagefttext($iOut, 13, 0, 300, 40, $white, $font_file, $user['name']);
imagepng($iOut,$photo);
$ret_obj = $facebook->api('/me/photos', 'POST', array(
'source' => '@' . $photo,
'message' => 'Hello',
)
);
unlink($photo);
?>
该应用程序正在获得用户发布的权限&在获得该权限后,从页面上传照片与从应用程序上传照片完全相同
首先,您必须从api合并用户名和照片中获取用户名
将其上载到用户配置文件,请阅读:
将照片上载到用户的个人资料
我将更新我的帖子,并用PHP为您提供完整的代码,好吗?你是php程序员吗?非常感谢这些代码。但现在如何在粉丝个人资料中发布图片的url。$photo='./mypic.png';//本地文件系统上照片的路径如何获取url$photo='./mypic.png';如果你想上传它:如果你的代码在这里example.com/index.php更改最后两行标题内容类型:image/png;imagepng$iOut,空;到这个$time=时间;imagepng$iOut,$time.'.png';&然后制作像这样的图片链接http://example.com“.$time.”.jpg“如果你的应用程序将有许多用户将$time从$time=time更改为$time=time+microtime,请上载图像,然后取消图像链接。”