How to post new feed on future date using graph API. If I add date in published in sense its throwing error as " with message: (#100) Param published must be a boolean "
if ( $session ) { try {
$request = new FacebookRequest(
$session,
'POST',
'/me/feed',
array (
'message' => 'Hi friends .... ',
'published' => "26/07/2015",
)
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
echo "<pre>"; print_r($graphObject); echo "</pre>";
} catch(FacebookRequestException $e) {
// echo "Exception occured, code: " . $e->getCode();
echo " with message: " . $e->getMessage();
}
}
Well, the published field IS a boolean, so it can only be true or false.
Btw, scheduling posts is only possible for Pages, there is no published parameter for /me/feed: https://developers.facebook.com/docs/graph-api/reference/v2.4/user/feed#publish
For a Page, you would set published to true and use a date in the scheduled_publish_time field: https://developers.facebook.com/docs/graph-api/reference/v2.4/page/feed#publish
Related
I am trying to list all videos from a Facebook Fan Page an i got some problems. I keep getting Facebook SDK returned an error: You must provide an access token.. I tried using the access token, but no use.
CODE :
use Facebook;
use Facebook\FacebookApp;
use Facebook\FacebookRequest;
use FileUpload\FacebookFile;
use FileUpload\FacebookVideo;
use Facebook\Authentication\AccessToken;
$expires = time() + 60 * 60 * 2;
$accessToken = new Facebook\Authentication\AccessToken('mytoken1234567890', $expires);
var_dump($accessToken);
$fb = new Facebook\Facebook([
'app_id' => 'XXX',
'app_secret' => 'XXX',
'access_token' => "mytoken1234567890",
'default_graph_version' => 'v2.5',
]);
$request = $fb->request('POST', '/uniladmag/videos');
try
{
$response = $fb->getClient()->sendRequest($request);
}
catch(Facebook\Exceptions\FacebookResponseException $e)
{
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e)
{
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
print_r($graphNode);
?>
OUTPUT :
object(Facebook\Authentication\AccessToken)#2 (2) {
["value":protected]=>
string(17) "mytoken1234567890"
["expiresAt":protected]=>
object(DateTime)#3 (3) {
["date"]=>
string(26) "2017-02-14 18:20:13.000000"
["timezone_type"]=>
int(3)
["timezone"]=>
string(13) "Europe/Berlin"
}
}
Facebook SDK returned an error: You must provide an access token.
What solutions do i have? Do i miss something?
Thanks.
i use facebook api for auto post from my website.
here is my code, after that i explain my problem:
require_once "Facebook/autoload.php";
$fb = new Facebook\Facebook([
'app_id' => 'xxxxxxx',
'app_secret' => 'xxxxxxxxx',
'default_graph_version' => 'v2.2'
]);
$pageAccessToken = 'xxxxxxxxxxxxxxxxxxxxx';
$linkData = [
'link' => $link,
'message' => $message,
'picture' => $pic
];
try {
$response = $fb->post('/me/feed', $linkData, $pageAccessToken);
} catch (Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
} catch (Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
}
$graphNode = $response->getGraphNode();
my problem is that, this code work sometimes, not all time.
and in sometime i see these errors:
Severity: Notice
Message: Undefined offset: 1
Filename: Http/GraphRawResponse.php
Line Number: 108
and
Severity: 4096
Message: Argument 4 passed to Facebook\FacebookResponse::__construct() must be of the type array, null given, called in /home/deponews/public_html/application/controllers/Facebook/FacebookClient.php on line 225 and defined
Filename: Facebook/FacebookResponse.php
Line Number: 75
i go to api explorer , and select my page from drop down and at the bottom drop down , select access page token , then select my page name again.
and copy generation token into my page access token.
i don't know why sometimes this code work well , and sometimes its not.
any idea ?
tnx
I'm using the tutorial here http://www.adamboother.com/blog/automatically-posting-to-a-facebook-page-using-the-facebook-sdk-v5-for-php-facebook-api/ to post to a facebook page using the PHP sdk.
I have create the app on Facebook, and I have created the Never Expire Page Access Token, which I have verified using the Access Token Debug Tool https://developers.facebook.com/tools/debug/accesstoken/
However, when I run my test code, it does NOT return any errors, but I get no posts on my page. I get a response back from my print_r($graphNode) of the following
Facebook\GraphNodes\GraphNode Object
(
[items:protected] => Array
(
[id] => 1204777049583245_1264619360265680
)
)
The code for my test post is below, can anyone explain to me WHY I am not getting any posts to show up?
define("FACEBOOK_APP_ID","MY APP ID");
define("FACEBOOK_APP_SECRET","MY APP SECRET");
define("FACEBOOK_APP_TOKEN","MY PAGE ACCESS TOKEN");
define("FACEBOOK_SDK_V4_SRC_DIR",$_SERVER['DOCUMENT_ROOT'].'/socialmedia/Facebook/src/Facebook/');
require_once($_SERVER['DOCUMENT_ROOT'].'/socialmedia/Facebook/src/Facebook/autoload.php');
$fb = new Facebook\Facebook([
'app_id' => FACEBOOK_APP_ID,
'app_secret' => FACEBOOK_APP_SECRET,
'default_graph_version' => 'v2.2',
]);
//Post property to Facebook
$linkData = [
'link' => 'www.yoururl.com',
'message' => 'test message'
];
$pageAccessToken = FACEBOOK_APP_TOKEN;
try {
$response = $fb->post('/me/feed', $linkData, $pageAccessToken);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: '.$e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: '.$e->getMessage();
exit;
}
$graphNode = $response->getGraphNode();
echo '<pre>';
print_r($graphNode);
echo '</pre>';
exit;
been wrestling with the facebook graph api a while now and am still not able to get what I want.
What am I missing? I have this code just as a test:
<?php
// );
$fb = new Facebook\Facebook([
'app_id' => '{313084575421679}',
'app_secret' => '{APP_SECRET}',
'default_graph_version' => 'v2.2',
]);
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get('/me?fields=id,name', '{APP_TOKEN}');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$user = $response->getGraphUser();
echo 'Name: ' . $user['name'];
?>
it gives me this error Graph returned an error: Invalid OAuth access token signature.
later I want to retrieve al, the photo's links so I can create a collage of the pictures in my album.
I'm playing around a bit with Facebook API + PHP SDK but I'm stuck..
I'm trying to fetch all my wall posts and (if attached) the images.
Fetching all my posts goes fine but it doesn't automatically include the image. So my main question is 'How can I add fields to the fetch command'
Here is the code I'm using now:
/* handle the result */
try {
$response = $fb->get('/me/posts', $token);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
// Page 1
$feedEdge = $response->getGraphEdge();
According to the facebook documents I should use this:
$request = new FacebookRequest(
$session,
'GET',
'/me/posts',
array(
'fields' => 'full_picture,message'
)
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
But the execute and getGraphobject method don't even exist in my SDK files (which is the latest version)
To get specific fields, you can try changing
$response = $fb->get('/me/posts', $token);
to
$response = $fb->get('/me/posts?fields=full_picture,message', $token);