将照片上传到页面时间轴Facebook SDK [英] upload photo to page timeline Facebook SDK
问题描述
我做了这个小应用程序,基本上要求用户登录并发布照片到FB页面。
的代码我已经很好的发布在你自己的墙上,但是当谈到发布到一个页面,我有一些困难。
I made this small app that basically asks a user to login and post a photo to a FB page. the code I have works great for posting on your own wall, but when it comes to posting to a page I am having some difficulties.
require_once('../src/facebook.php');
$config = array(
'appId' => 'XXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXX',
'fileUpload' => true,
);
$facebook = new Facebook($config);
$user_id = $facebook->getUser();
$photo = realpath("mypic.png"); // Path to the photo on the local filesystem
$message = 'Photo upload via the PHP SDK!';
if($user_id) {
try {
$ret_obj = $facebook->api('/PAGE_ID_HERE_??/photos', 'POST', array(
'source' => '@' . $photo,
'message' => $message,));
如果我使用feed而不是照片,像这样
if i use feed instead of photos, like here
$facebook->api('/PAGE_ID_HERE_??/FEED',
它可以工作,但只发布消息
i需要所有权限:
user_photos user_videos publish_action
manage_pages publish_stream
it works, but only posts the message.
i have all permissions needed:
user_photos user_videos publish_action
manage_pages publish_stream
推荐答案
要与页面进行交互,您需要用户的访问令牌,用户需要是管理者或内容创建者页面,那些令牌是每个用户每页。
To interact with the page you need the access token of the user. The user needs to be the 'manager' or 'content creator' of the page. And those tokens are per user per page.
我有一个PHP示例,它使用cURL调用来处理,我认为这是一个想法。 >
I have a PHP example where this is handled using a cURL call. I think it gives the idea.
$ch = curl_init();
$url = "https://graph.facebook.com/" . $album_id . "/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);
$retdata = curl_exec($ch);
echo($retdata);
在这一个中, $ album_id
是该页面的相册ID和 $ access_token
是该页面用户的访问令牌。
In this one the $album_id
is the album id of the page and the $access_token
is the access token for the user for the page.
另外< a href =https://developers.facebook.com/blog/post/498/ =nofollow>这是Facebook的一个例子,一张个人相册。您可以查看相册ID和令牌,并使用该方法。
Also here's an example by Facebook for a personal album. You can chage the album ID and the token and use that approach.
这篇关于将照片上传到页面时间轴Facebook SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!