问题
Okay, there maybe many question same to me. But I can not solve how to handle in my case. Let start:
I develop a property listing website. The flowchart is simple. User can posting as many as they want using facebook login.
Now they all are okay. I also can solve about how whenever user finish their posting, it will automatically post to their personal/user wall page.
But I want that every listing should be also posted on MY property listing page. Whether it will post as user who make the posting or as page name, no problem. But I need to make sure it not use my personal/user/admin of the page.
So I can't find any answer how to solve this. How in a single website session, my script can post to the user wall who make the posting, and also post to my page. If it prohibited for user who are a foreigner and not the admin to post to my page, then how to make post to my page under the name of the page itself, when the facebook api created is belong to the user. Do I need to create different facebook api object? Need help..thank you for anyone who can help me. Really appreciated.
Below is the code I have use:
$attachment = array(
'message' => FB_STREAM_MSG,
'picture' => $imgsrc,
'link' => $seourl,
'name' => $prop_name,
'caption' => FB_STREAM_CAP,
'description' => substr($prop_desc,0,150) . '..',
);
$facebook->api("/$user/feed", 'POST', $attachment);
//$facebook->api("/".FB_PAGE_ID, 'POST', $attachment); //this doesn't work.
回答1:
Ok...problem all SOLVED!
To POST to other user wall, the user need to sign in to generate user token and code as usually like this:
$attachment = array(
'message' => ClearText_FB($prop_name),
'picture' => $imgsrc,
'link' => $seourl,
'name' => ClearText_FB($prop_name),
'caption' => FB_STREAM_CAP,
'description' => ClearText_FB(substr($prop_desc,0,150) . '..'),
);
$facebook->api("/$user/feed", 'POST', $attachment);
And to post to our own page wall, it doesn't matter who is the user, whether the user is the admin or not of the page. But it matters to get the page access token to grant the application to post to page wall. The fb docs said the page access token will last forever, so we just need to get once and save it for next use.
To get page access token for the first time:
$page_access_token = "";
$result = $facebook->api("/me/accounts");
foreach($result["data"] as $page) {
if($page["id"] == $page_id) {
//$page_access_token = $page["access_token"];
$page_access_token = $facebook->api("/".FB_PAGE_ID."?fields=access_token");
break;
}
}
Then save the $page_access_token value to server/db or file. Code above doesnt need anymore. Comment out or just remove it. Remove 'name' field as it seems will place post under other user post section. This will post to page wall as page not as user:
$attachment = array(
'message' => ClearText_FB($prop_name),
'picture' => $imgsrc,
'link' => $seourl,
'description' => ClearText_FB(substr($prop_desc,0,150) . '..'),
'access_token' => $page_access_token,
);
$facebook->api("/".FB_PAGE_ID.'/feed', 'POST', $attachment);
来源:https://stackoverflow.com/questions/19134605/facebook-api-how-to-post-to-my-own-wall-page