how to post 360 panoroma to facebook using php SDK? - php

How to post the 360degree image to Facebook using PHP Facebook SDK v5?
I tried using this parameter 'allow_spherical_photo'=> true, But it is not working.
Posting image as simple flat image.
here is my code
$message = '';
$title = '';
$link = 'http://google.com/';
$description = 'My Image Posting';
$url = 'My Public image url';
$caption = 'My Image';
$attachment = array(
'message' => $message,
'name' => $title,
'allow_spherical_photo'=> true,
'source' => $url,
'description' => $description,
'photo'=>$url,
);
echo "<pre>";
print_r($attachment);
try{
echo "try";
//Post to Facebook
$fb->post('/me/feed', $attachment, $accessToken);
//Display post submission status
echo 'The post was submitted successfully to Facebook timeline.';
}catch(FacebookResponseException $e){
echo 'Graph returned an error: ' . $e->getMessage();
exit;
}catch(FacebookSDKException $e){
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
can anyone help me out? I searched a lot.

Related

Uploading video onto Facebook using Facebook PHP SDK gives me no error but no video uploaded?

I'm trying to Post a video onto Facebook using Facebook php SDK and Facebook graph and I get a strange response back.
it shows a success but null video ID!
This is the response I get:
{"video_id":null,"success":true}
And this is my code:
$fb = new Facebook\Facebook([
'app_id' => 'XXX',
'app_secret' => 'XXXXX',
'default_graph_version' => 'v2.9',
]);
$accessToken = 'XXXXXX';
try {
$videoTitle = 'FOO';
$videoDescription = 'BAR';
$data = [
'title' => $videoTitle,
'description' => $videoDescription,
];
$response = $fb->uploadVideo('/me/', '/var/www/vhosts/SITE.co.uk/httpdocs/video.mp4', $data, $accessToken);
} catch(Facebook\Exception\ResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exception\SDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
//echo 'Video ID: ' . $response;
echo json_encode($response);
I don't know whats causing this and I have spent hours trying to figure this out.
any help would be appreciated.

How to upload a video to Facebook event page via PHP

I have created an event on my test page and I'm going to upload a video to that event page from my web site. I have used the below code but it is doesn't work.
$data = [
'title' => 'test Video',
'description' => 'This is test video',
'source' => $fb->videoToUpload($video_path),
];
try {
$response = $fb->post('/' . $event_id . '/videos', $data, $page_token);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
return 'Graph returned an error: ' . $e->getMessage();
} catch(Facebook\Exceptions\FacebookSDKException $e){
return 'Facebook SDK returned an error: ' . $e->getMessage();
}
$graphNode = $response->getGraphNode();
I got this error.
Graph returned an error:(#33) This object does not exist or does not support this action.
So I fix some parts like this.
$data = [
.......
'source' => $video_path
];
try{
$response = $fb->post('/' . $event_id . '/feed', $data, $page_token);
}
.......
Then it works like this.
But I want to result like as this picture.
How shall I do?
Official reference for post video on event (Api Graph v5.0):
Upload:
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.2',
]);
$data = [
'title' => 'My Foo Video',
'description' => 'This video is full of foo and bar action.',
'source' => $fb->videoToUpload('/path/to/foo_bar.mp4'),
];
try {
$response = $fb->post('/me/videos', $data, 'user-access-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;
}
$graphNode = $response->getGraphNode();
var_dump($graphNode);
echo 'Video ID: ' . $graphNode['id'];
POST ON EVENT:
/* PHP SDK v5.0.0 */
/* make the API call */
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->get(
'/{event-id}/videos',
'{access-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;
}
$graphNode = $response->getGraphNode();
/* handle the result */
If you see the result JSON :
{
"data": [],
"paging": {}
}
All reference:
-Start - Initialize an upload session
-Transfer - Upload video chunks
-Finish - Post the video
In the function:
private function postFBVideo($authResponse, $fileObj, $formData)
{
FacebookSession::setDefaultApplication('yourAppkey', 'yourAppSecret');
$ajaxResponse = '';
try {
$session = new FacebookSession($authResponse->accessToken);
} catch (FacebookRequestException $ex) {
// When Facebook returns an error
$ajaxResponse = 'FB Error ->' . json_encode($ex) ;
} catch (\Exception $ex) {
// When validation fails or other local issues
$ajaxResponse = 'FB Validation Error - ' . json_encode($ex) ;
}
if ($session) {
$response = (new FacebookRequest(
$session, 'POST', '/.$idevent./videos', array(
'source' => new CURLFile('path', 'video/MOV'),
'message' => $formDataMessage,
)
))->execute();
$ajaxResponse = $response->getGraphObject();
}
return json_encode($ajaxResponse);
}

Tag persion in page post/photo with Facebook SDK

I can programmatically post on behalf of a page. I want to be able to post to a person, or tag them in the post, or tag them in a comment. I just need anyway to create a post as a page, and have it tied to a user.
Edit: I just really want to be able to make a page post, and tag a user, or tag them in a comment, or tag them in a photo. Any form of tagging where they'd be notified.
I've tried tagging people in a photo. The tags appear as pending, there's no notification, and when I approve the tag, it vanishes permanently. So probaly not possible.
Here's my code so far:
<?php
$pageId = 'removed';
// Pass session data over.
// Include the required dependencies.
require( __DIR__.'/facebook/autoload.php' );
session_start();
//$_SESSION["accessToken"] = null;
// Initialize the Facebook PHP SDK v5.
$fb = new Facebook\Facebook([
'app_id' => 'removed',
'app_secret' => 'removed',
'default_graph_version' => 'v2.5',
]);
if(isset($_SESSION["accessToken"])){ //if authorized
$photo = [
'message' => 'Test message.',
'source' => $fb->fileToUpload('glow.jpg'),
'tags' => array(
array(
'tag_uid'=> removed,
'tag_text' => 'name',
'x' => '50',
'y' => '50',
)
)
];
//auth page
$response = $fb->get('/' . $pageId . '?fields=access_token', $_SESSION["accessToken"]);
$pageNode = $response->getGraphNode();
$pageToken = $pageNode['access_token'];
$response = $fb->post('/' . $pageId . '/photos', $photo, $pageToken);
$postNode = $response->getGraphNode();
$postId = $postNode['id'];
echo 'Page Token: ' . $pageToken . '<br />Post Id:' . $postId;
$response = $fb->post('/' . $postId . '/comments', array (
'message' => 'This is a test comment. #[{19292868552}:1:{Martin Firth}] tag thing.',
), $_SESSION["accessToken"]);
} else { //not authorized yet
$helper = $fb->getRedirectLoginHelper();
$accessToken = $helper->getAccessToken();
$_SESSION["accessToken"] = $accessToken;
// Send the request to Graph
try {
$response = $fb->get('/' . $pageId . '?fields=access_token', $accessToken);
} 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();
$permissions = ['email', 'user_likes', 'publish_pages', 'publish_actions'];
$loginUrl = $helper->getLoginUrl('http://localhost/terranova/site/', $permissions);
echo ' Log in with Facebook!';
exit;
}
}
?>

Facebook PHP SDK v5 Post to Fan Page

I would like to use the Facebook PHP SDK v5 to automatically post to a FAN PAGE. I have the code below which successfully posts to my own wall, but how do I alter the code to post to my fan page? From what I've read, I need to pass in the page id of the fan page?
$params["message"] = 'test';
$params["link"] = 'https://example.com';
$params["picture"] = 'https://example.com/images/logo_hod.jpg';
$params["description"] = 'testtt';
$access_token = $accessToken;
try {
$response = $fb->post('/me/feed', $params, $access_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;
}
$graphNode = $response->getGraphNode();
echo 'Posted with id: ' . $graphNode['id'];
I tried replacing this line:
$response = $fb->post('/me/feed', $params, $access_token);
with this to substitute in the fan page id:
$response = $fb->post('/229107363768165/feed', $params, $access_token);
and got the error:
Graph returned an error: Unsupported post request.
UPDATE: I also made the app "public" in an attempt to get past the "unsupported post request" error. No luck.
i think your $params is not right.
I use this:
$fb = new Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v2.2',
]);
$params = [
'link' => 'https://example.com',
'photo' => 'https://example.com/images/logo_hod.jpg',
'message' => 'A test post!',
];
try {
// Returns a `Facebook\FacebookResponse` object
$response = $fb->post('/me/feed', $params, '{access-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;
}
Post Links Using the Graph API
I assumes that you've already obtained an access token and the access token must have the publish_actions permission for this to work.

can't post photos Facebook Page's Timeline as Page (PHP)

I want to post Photos on may Facebook Page's Timeline as Page not user using PHP SDK
Here is the sample code that I'm using
<?php
include_once("config.php");
if($_POST)
{
if(strlen($_POST["message"])<1)
{
//message is empty
$userMessage = 'No message!';
}
//Post variables we received from user
$userPageIds = '00000000000000';
$facebook->setFileUploadSupport(true);
$userMessage = $_POST["message"];
//HTTP POST request to PAGE_ID/feed with the publish_stream
$post_url = '/'.$userPageId.'/albums';
//*
// posts message on page feed
$page_info = $facebook->api("/$userPageId?fields=access_token");
$access_token = $facebook->getAccessToken();
// Get the new album ID
$albums = $facebook->api($userPageId.'/albums','GET',array('access_token'=>$access_token));
foreach($albums['data'] as $album)
{
echo $album['name'];
if($album['name'] == 'Timeline Photos')
{
$album_id = $album['id'];
}
}
$args = array(
'message' => $userMessage,
'image' => '#' . $_FILES['img']['tmp_name'],
'aid' => $album_id,
'no_story' => 0,
'access_token' => $page_info['access_token']
);
if ($fbuser) {
try {
$postResult = $facebook->api('/'.$album_id.'/photos', 'post', $args);
} catch (FacebookApiException $e) {
echo $e->getMessage();
}
}else{
$loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions));
header('Location: ' . $loginUrl);
}
//Show sucess message
}
?>
this code add the photo to the Page's Timeline album , but it doesnt appear in the page's wall
Any help is greatly appreciated.

Categories