我正在通过Graph API创建一些帖子,但我需要获取其ID才能在以后使用它。
这是我在PHP中使用的代码,有人可以帮我展示如何在创建帖子后获取ID吗?
我尝试执行$ response-> id或$ graphObject-> id,但它不起作用。另外,我需要在代码的最后一行使用这个$ graphObject吗?我在其他地方看到了它,但我不知道它做了什么。
我在$ graphObject中做了一个print_r并收到了这个aswer: Facebook \ GraphObject对象([backingData:protected] =>数组([id] => 741760479220480))
由于
<?php
session_start();
require_once( 'Facebook/FacebookHttpable.php' );
require_once( 'Facebook/FacebookCurl.php' );
require_once( 'Facebook/FacebookCurlHttpClient.php' );
require_once( 'Facebook/FacebookSession.php' );
require_once( 'Facebook/FacebookRedirectLoginHelper.php' );
require_once( 'Facebook/FacebookRequest.php' );
require_once( 'Facebook/FacebookResponse.php' );
require_once( 'Facebook/FacebookSDKException.php' );
require_once( 'Facebook/FacebookRequestException.php' );
require_once( 'Facebook/FacebookClientException.php' );
require_once( 'Facebook/FacebookOtherException.php' );
require_once( 'Facebook/FacebookAuthorizationException.php' );
require_once( 'Facebook/FacebookPermissionException.php' );
require_once( 'Facebook/FacebookServerException.php' );
require_once( 'Facebook/GraphObject.php' );
require_once( 'Facebook/GraphSessionInfo.php' );
require_once( 'Facebook/GraphUser.php' );
use Facebook\FacebookHttpable;
use Facebook\FacebookCurl;
use Facebook\FacebookCurlHttpClient;
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
use Facebook\FacebookRequest;
use Facebook\FacebookResponse;
use Facebook\FacebookSDKException;
use Facebook\FacebookRequestException;
use Facebook\FacebookClientException;
use Facebook\FacebookOtherException;
use Facebook\FacebookAuthorizationException;
use Facebook\FacebookPermissionException;
use Facebook\FacebookServerException;
use Facebook\GraphObject;
use Facebook\GraphSessionInfo;
use Facebook\GraphUser;
FacebookSession::setDefaultApplication('app','password');
$session = new FacebookSession('token');
$message = 'Test';
$link = "http://www.example.com.br";
$description = 'Description';
$name = 'Name';
$caption = 'Caption';
$request = new FacebookRequest(
$session,
'POST',
'/page_id/feed',
array (
'message' => $message,
'link' => $link,
'description' => $description,
'published' => 'false',
'name' => $name,
'caption' => $caption,
)
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
?>
答案 0 :(得分:0)
根据https://developers.facebook.com/docs/graph-api/reference/v2.0/user/feed/#publish,它应该是
$post_id = $graphObject->id;
答案 1 :(得分:0)
解决它!
$post_id = $graphObject->getProperty('id');