Get Facebook video thumbnail image URLs? - facebook

We can get the video thumb of YouTube videos by using the video ID in an URL the way defined below
$src = "http://img.youtube.com/vi/".$video_id."/default.jpg";
Similarly, how can I get the video thumb of Facebook videos? Is there any predefined URL in which we put the Facebook video ID and get the as like youtube defined in the way above?

Trying to do this as well but it does not appear so.
Example:
a video I have on a Page with
ID "1015030122022040"
has a thumbnail url of:
http://vthumb.ak.fbcdn.net/hvthumb-ak-ash2/51388_10150301225830401_10150301220220401_62962_1470_t.jpg
While another video with ID: 10150361184550401
has a thumbnail url of:
http://vthumb.ak.fbcdn.net/hvthumb-ak-snc4/162098_10150361242815401_10150361184550401_35242_2053_t.jpg
I looked through others and found no obvious pattern. You can however do an FQL to return the array of videos by uid.
Using some code from a tutorial, I edited the "sql query example" in Step Three to this:
try {
//get user id
$uid = $facebook->getUser();
//or you can use $uid = $fbme['id'];
$fql = "SELECT vid, owner, title, description, thumbnail_link, embed_html, updated_time, created_time FROM video WHERE owner=" . $uid;
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
}
catch(Exception $o){
d($o);
}
Then from his example was able to the view the arrays <?php d($fqlResult); ?>
And grabbed my most recent video thumbnail thusly:
<img src="<?php echo $fqlResult[0][thumbnail_link]; ?>" />

check this :http://www.cutevideoclub.com/php/facebook-video-thumbnail-with-video-id-php/
$fbvideoid="158952527492492";
$fql2 = "SELECT vid, owner, title, description, thumbnail_link, embed_html, updated_time, created_time FROM video WHERE vid=" . $fbvideoid;
use above query for detail see ref site:http://www.cutevideoclub.com/php/facebook-video-thumbnail-with-video-id-php/
or click here facebook video thumbnail with video id php

Related

How to create post with multiple images on fb api? [duplicate]

Now I posting a single photo to wall like this:
$response = $facebook->api("/$group_id/photos", "POST", array(
'access_token=' => $access_token,
'message' => 'This is a test message',
'url' => 'http://d24w6bsrhbeh9d.cloudfront.net/photo/agydwb6_460s.jpg',
)
);
It works fine, but can I somehow post a multiple photos, something like this:
You can now publish multiple images in a single post to your feed or page:
For each photo in the story, upload it unpublished using the {user-id}/photos endpoint with the argument published=false.
You'll get an ID for each photo you upload like this:
{
"id": "10153677042736789"
}
Publish a multi-photo story using the {user-id}/feed endpoint and using the ids returned by uploading a photo
$response = $facebook->api("/me/feed", 'POST',
array(
'access_token=' => $access_token,
'message' => 'Testing multi-photo post!',
'attached_media[0]' => '{"media_fbid":"1002088839996"}',
'attached_media[1]' => '{"media_fbid":"1002088840149"}'
)
);
Source: Publishing a multi-photo story
You can make batch requests as mentioned here: https://stackoverflow.com/a/11025457/1343690
But its simple to loop through your images and publish them directly.
foreach($photos as $photo)
{
//publish photo
}
Edit: (regarding grouping of photos on wall)
This grouping is done by facebook automatically if some photos are uploaded into the same album.
Currently you cannot create an album in a group via Graph API - it is not supported (as of now), see this bug.
But you can do this - create an album manually, then get the album_id by-
\GET /{group-id}/albums, then use the the code with album_id instead of group_id-
foreach($photos as $photo){
$facebook->api("/{album-id}/photos", "POST", array(
'access_token=' => $access_token,
'name' => 'This is a test message',
'url' => $photo
)
);
}
I've tested it, see the result-
Actually you can upload a multi story photo(I did it using Graph Api and PHP) but the problem comes if you need scheduled this post.Your post is schedule but also it shows on the page's feed.
P.S. I'm using Graph Api v2.9
PHP Code
$endpoint = "/".$page_id."/photos";
foreach ($multiple_photos as $file_url):
array_push($photos, $fb->request('POST',$endpoint,['url' =>$file_url,'published' => FALSE,]));
endforeach;
$uploaded_photos = $fb->sendBatchRequest($photos, $page_access_token);
foreach ($uploaded_photos as $photo):
array_push($data_post['attached_media'], '{"media_fbid":"'.$photo->getDecodedBody()['id'].'"}');
endforeach;
$data_post['message'] = $linkData['caption'];
$data_post['published'] = FALSE;
$data_post['scheduled_publish_time'] = $scheduled_publish_time;
$response = $fb->sendRequest('POST', "/".$page_id."/feed", $data_post, $page_access_token);
$post_id = $cresponse->getGraphNode()['id'];
You will need to upload each photo first with published state to false, and then use the ID's of the unpublished photos to the /me/feed endpoint to schedule the photo. The schedule needs to be within the 24 hours from the time the photos are uploaded as facebook deletes all unpublished photos in 24 hours.
Ref:
https://developers.facebook.com/docs/graph-api/photo-uploads/
There is no way to publish more than one photo in the same graph API call.
See documentation: https://developers.facebook.com/docs/graph-api/reference/user/photos

upload photos got by fql query on my server

Hello guys i'm trying to understand how to upload the image from facebook.
function for do fql query. Is useful for future occasions.
<?php
// connection facebook api key...
function fb_fql($fql) {
$this->ci =& get_instance();
// Get User Details
$this->ci->load->model('facebook_model');
$this->ci->load->library('user');
// $fb_id = $this->ci->user->get_facebook_id($this->ci->session->userdata('user_id'));
// User is found
// Get Facebook User profile
$user_profile = $this->ci->facebook->getUser();
$result = false;
if ($user_profile) { // if profile exist
try{
$accessToken = $this->ci->facebook->getAccessToken();
$fb_id = $this->ci->facebook->api('/me?access_token='.$accessToken);
if( isset($user_profile) )
{
$fql_run = array(
'method' => 'fql.query',
'query' => $fql,
);
$result = $this->ci->facebook->api($fql_run); // run fql
} else { $result = false; }
}catch(FacebookApiException $e){
$result = null;
}
}
return $result;
}
?>
Here i get the photos by this query and the result of the array show correctly 10 photos of facebook. Now i have to upload it on my server but how can i do that?
<?php
// fql query
$fql = "SELECT pid
FROM photo
WHERE aid IN (
SELECT aid
FROM album
WHERE owner=me() LIMIT 10
) ";
// run query
$photos = $this->facebook_action->fb_fql($fql);
if ($photos != false) {
foreach ($photos as $photo) {
echo print_r($photos); // show the array with the data taken
// here i would like upload the photos got from the query.
}
} else {
echo "no photo";
}
?>
You will need to get the src or src_big field from the photo table and then download this using CURL, file_put_contents or similar. There are quite a few StackOverflow answers for grabbing an image and saving it to a file - e.g Saving image from PHP URL
SELECT src_big FROM photo
WHERE aid IN (SELECT aid FROM album WHERE owner=me() LIMIT 10)
Since you will be downloading user's data to your own server, I would advise you to check that your application does not violate the Facebook Platform Policy.

list users who like page or url

I need to list users who like specific url or at least facebook page
I tried using both PHP and https://api.facebook.com/method/fql.query
I can see the number of likers for the URL
$arr[1]['url'] = 'http://example.com/test/test3.php?ref=gametest&fb_ref=gametest&fb_source=gametest';
$arr[1]['object_id'] = '10150930574980642';
require_once("facebook.php");
$facebook = new Facebook(array(
'appId' => '325617367526193',
'secret' => '6c40e01dd717431c9b7ec6ce68bf0c94',
));
I used http://developers.facebook.com/docs/reference/fql/like/ example to form similar query
$query = <<<FQL
SELECT user_id FROM like WHERE object_id="10150930574980642"
FQL;
$fql_query_url = 'https://graph.facebook.com/fql?q=' . rawurlencode ( $query );
$fql_query_url .= '&access_token=' . rawurlencode ( $facebook->getAccessToken() );
but the resulting link gives no data at all
{
"data": [
]
}
The same result via link with or without access_token
api.facebook.com/method/fql.query?query=SELECT%20user_id%20FROM%20like%20WHERE%20object_id%3D%2210150930574980642%22
The "like" table will only return the IDs of users who like the following objects (video, note, link, photo, or album).
You cannot find out the user Ids of people who like a particular page, only objects within that page.
e.g. The likes for an album on the Facebook Page (SELECT user_id FROM like WHERE object_id="10150146071791729"&access_token=[access_token])
If you want to get the users that have liked a particular link, you will need to get the object_id of this link first:
https://api.facebook.com/method/fql.query?query=SELECT url,site,id FROM object_url WHERE url IN ('http://developers.facebook.com')
This will return the object_id of the link http://developers.facebook.com.

facebook post image to user wall and image store in my fan page album

Isn't possible facebook allow us from my apps post or share image to user wall and then at the same time the user image will store in my fan page album?
And suggestion and opinion how to do it? hopefully you guy able provide some code for me
step1
$user = $facebook->getUser();
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => 'email,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown,user_photos'
)
);
step2 , 4 ,5
$file='images/'.$_FILES["file"]['name'];
if( move_uploaded_file($_FILES["file"]["tmp_name"],$file))
{
$facebook->setFileUploadSupport(true);
$post_data = array(
'name'=>$_POST['album'],
'description'=>$_POST['album']
);
$data['album'] = $facebook->api("/me/albums", 'post', $post_data);
//$file = $file_name;
$post_data = array(
"message" => $_POST['message'],
"source" => '#' . realpath($file)
);
$album_id = $data['album']['id'];
$data['photo'] = $facebook->api("/$album_id/photos", 'post', $post_data);
}
it is possible...steps
take user publish stream permissions - scope - publish_stream,user_photos
set application for uploading image..setFileUploadSupport(true);
send the image to users wall using feed api
fetch user photo
Upload it on pages' album by albums api

Working with facebook Like button and FSQL

I have develop Facebook application and added page tab on my page.
I have read Facebook documentation for canvas application development and adding application on page tab.
I want to show different page for people who click on Like button on my page and different page to people who not click on like button.
After reading documentation I found that it is possible using FSQL but I am not getting any result from my sql queries
https://developers.facebook.com/docs/reference/fql/url_like/
https://developers.facebook.com/docs/reference/fql/
require_once 'facebook.php';
// *** Add your Facebook API Key, Secret Key here ***
$appapikey = '*********';
$appsecret = '**********';
$facebook = new Facebook($appapikey, $appsecret);
// $user_id = $facebook->require_login();
//$fql = "select name from user where uid=me()";
//$fql = "SELECT user_id FROM like WHERE object_id='122706168308'";
$fql = "SELECT user_id, object_id, post_id FROM like WHERE user_id=me()";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
echo"hi";
echo"<pre>";
print_r($fqlResult);
echo"</pre>";
Any idea how to make it working?
Thanks.
did you authorized app at first ?
PS: its not FSQL its fql i mean you are not able to use all sql commands in fql