我正在使用FB图形api将内容发布到用户的墙上。我最初尝试使用这种方法:
$wall_post = array(array('message' => 'predicted the', 'name' => 'predicted the'),
array('message' => $winning_team, 'name' => $winning_team, 'link' => 'http://www.sportannica.com/teams.php?team='.$winning_team.'&year=2012'),
array('message' => 'to beat the', 'name' => 'to beat the',),
array('message' => $losing_team, 'name' => $losing_team, 'link' => 'http://www.sportannica.com/teams.php?team='.$losing_team.'&year=2012'),
array('message' => 'on '.$game_date.'', 'name' => 'on '.$game_date.''),
array('picture' => 'http://www.sportannica.com/img/team_icons/current_season_logos/large/'.$winning_team.'.png'));
$res = $facebook->api('/me/feed/', 'post', '$wall_post');
但是,令我惊讶的是,您不能将多个链接发布到用户墙。
所以,现在我正在使用图形 api 将内容发布到用户的墙上,就像 Spotify 所做的那样。所以,现在我已经发现我需要使用打开的图形仪表板创建自定义操作和对象。因此,我创建了"预测"操作,并授予它编辑对象"游戏"的权限。
所以,现在我有了代码:
$facebook = new Facebook(array(
'appId' => 'appID',
'secret' => 'SECRET',
'cookie' => true
));
$access_token = $facebook->getAccessToken();
$user = $facebook->getUser();
if($user != 0)
{
curl -F 'access_token='$.access_token.'' '
-F 'away_team=New York Yankees' '
-F 'home_team=New York Mets' '
-F 'match=http://samples.ogp.me/413385652011237' '
'https://graph.facebook.com/me/predict-edit-add:predict'
}
我不断收到错误:
解析错误:语法错误、意外T_CONSTANT_ENCAPSED_STRING
有什么想法吗?
PHP 不是 shell 脚本语言。您不能简单地输入一个 shell 命令并期望它工作。
与其尝试调用curl
程序(例如,您可以使用system()
或exec()
),您可以简单地使用curl PHP扩展或Facebook API中的适当函数。
混合PHP代码和执行curl
命令,你应该从shell调用它:
curl -F 'access_token='$.access_token.'' '
-F 'away_team=New York Yankees' '
-F 'home_team=New York Mets' '
-F 'match=http://samples.ogp.me/413385652011237' '
'https://graph.facebook.com/me/predict-edit-add:predict'
或者使用 PHP-SDK 实现相同的目标:
$facebook->api('/me/predict-edit-add:predict', 'post', array(
'away_team'=>'New York Yankees',
'home_team'=>'New York Mets',
'match'=>'http://samples.ogp.me/413385652011237'
));