问题描述
我正在将我的网络游戏整合到Facebook游戏中。 Facebook登录,获取用户ID,获取用户个人资料图片可以。但是我需要发布一些墙壁(例如,John Doe赢得了50分!)。我的Facebook应用程序拥有 offline_access 和 publish_Stream 权限。
现在我想自动发布一些链接。我正在使用与。
我可以获得Facebook用户ID等...但我不知道我可以自动(例如当用户离线时)将某些东西发布到用户的墙壁。
我正在寻找的发布标题。但是我需要access_token参数来使用它。我不知道这个access_token在哪里。
PHP-SDK 3.1.1 / h2>
生成应用和用户令牌。 $ app_access_token & $ access_token
*如果您有离线访问权限,用户access_token将永远不会过期,除非用户取消授权您的应用。当您离线或不与您的应用程序进行互动时,您需要用于发布到用户墙。*
<?php
require'./src/facebook.php';
$ facebook = new Facebook(array(
'appId'=>'135669679827333',
'secret'=>'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
));
$ user = $ facebook-> getUser();
if($ user){
try {
//继续知道你有一个登录的用户被认证。
$ user_profile = $ facebook-> api('/ me');
} catch(FacebookApiException $ e){
error_log($ e);
$ user = null;
}
}
if($ user){
$ logoutUrl = $ facebook-> getLogoutUrl();
} else {
$ loginUrl = $ facebook-> getLoginUrl();
}
//创建应用程序访问令牌
$ app_access =https://graph.facebook.com/oauth/access_token?client_id=135669679827333&client_secret=xxxxxxxxxxxxxxxxxxxxxx&grant_type=client_credentials;
$ app_access_token = file_get_contents($ app_access);
//如果我们有一个登录用户,请创建具有会话的access_token。
if($ user){
$ access_token = $ _SESSION ['fb_135669679827333_access_token'];
}
?>
I'm integrating my web-based game to a Facebook Game . Facebook login, getting user id, getting user profile picture is OK . But i need to post somethings to wall (For example, John Doe earned 50 point!) .
I have offline_access and publish_Stream permissions for my Facebook App.
Now i want to publish some links automatically. I'm using Facebook PHP SDK with Yii.
I can get Facebook User ID etc... But i don't know how can i post somethings to user's wall, automatically (for example when user is offline).
I'm looking Graph API Post document's Publishing title. But i need access_token parameter for use this. And i'm not sure where is this access_token .
PHP-SDK 3.1.1
To generate app and user tokens. $app_access_token & $access_token
*The user access_token if you have offline access will never expire, unless user deAuthorizes your app. You would need to use for posting to a users wall when they are offline or not interacting with your application.*
<?php
require './src/facebook.php';
$facebook = new Facebook(array(
'appId' => '135669679827333',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
));
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
$logoutUrl = $facebook->getLogoutUrl();
} else {
$loginUrl = $facebook->getLoginUrl();
}
// Create Application Access Token
$app_access = "https://graph.facebook.com/oauth/access_token?client_id=135669679827333&client_secret=xxxxxxxxxxxxxxxxxxxxxxxx&grant_type=client_credentials";
$app_access_token = file_get_contents($app_access);
// If we have a user who is logged in, create access_token with session.
if ($user) {
$access_token = $_SESSION['fb_135669679827333_access_token'];
}
?>
这篇关于使用Facebook PHP SDK发布到用户的Facebook墙的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!