I am trying to use URL as a video source to create a video post on Facebook using facebook's PHP SDK for graph API. I am trying to use uploadVideo method from the example given on https://developers.facebook.com/docs/php/howto/example_upload_video/
This method gives error
filesize(): stat failed for <URL>
It is trying to read file by using filesize() and it is not possible to use URL as the source.
The problem is while making the POST request to Facebook I have only access to the video URL and it will not be feasible to download on the local machine and post it to Facebook.
So is there other methods to use URL to post a video to Facebook?
After going through the source code for PHP SDK and how the uploadVideo method work. I found 'videoToUpload' method.
$response = $facebook->post('/'.$fb_page_id.'/videos', array(
'description' => $postData['description'],
'source' => $facebook->videoToUpload($media)
), $access_token);
This method works. But I am not sure if this is the right way to go.
Related
Hello everyone,
I was working on a project where i need to display a video specifically from my google drive on a webpage. I don't want to manually select the video and copy its embed code, is there a way we can obtain the embed code for a video using google api (PHP preferred) ?
So that i can use this code within an iframe and display the video.
Please also suggest if there are other ways.
Thanks in advance,
You can start with Google Drive API https://developers.google.com/drive/v3/web/quickstart/php and this segment of code i hope can help you.
<?php
// New Google Client, see all settings at link in description
$client = new Google_Client();
// New Google Drive Service
$service = new Google_Service_Drive($client);
// Params with filter of MIME type for search only videos mp4 (you can change this)
$optParams = [
'q' => "mimeType='video/mp4'",
'pageSize' => 10,
'fields' => 'nextPageToken, files(id, name, webViewLink)'
];
// Get files from our request
$files = $service->files->listFiles($optParams);
// Print an iframe for each video
foreach($files->files as $file){
// Now I need to make a little detail about the next lines of code so look at [Info]
$src = str_replace('/view', '/preview', $file->webViewLink);
echo '<iframe width="500" height="200" target="_parent" src="'. $src .'"></iframe>'
}
?>
[Info]
The objects returned from $service->files->listFiles($optParams) are Google_Service_Drive_DriveFile objects and each of these have a series of properties. From v3 of Google API a properties called embedLink was removed and there isn't an alternative for this property from v2(Migrate to Google Drive API v3) so as you seen in my code i use webViewLink property that return a URL to a view of file like this:
https://drive.google.com/file/d/123456789/view
But if you use this URL inside an <iframe> the browser notice to you an error:
Refused to display 'https://drive.google.com/file/d/123456789/view' in a frame because it set 'X-Frame-Options' to 'sameorigin'.`
I'm not holding you too much on this issue and there are a lot of question about this. So we need to request a preview of file and not a view an i do that with
str_replace('/view', '/preview', $file->webViewLink);
on the URL returned by the request. Now you can use this URL in a <iframe>
I need some help on a youtube api called thumbnails:set.
I implemented oauth to my account, already a youtube partner and got a developer key.
I would want to know on how to use the HTTP request which is "POST https://www.googleapis.com/youtube/v3/thumbnails/set" with videoId as its parameter and implement it in php.
In general, I would like to know how to upload a custom thumbnail and pass it using the API towards youtube.
here's the link of the api: https://developers.google.com/youtube/v3/docs/thumbnails/set#try-it
You can use the YouTube php client library. You will use
$setResponse = $youtube->thumbnails->set("YOUR_VIDEO_ID",
array('mediaUpload' => $media));
where media is your media upload as in
$media = new Google_MediaFileUpload('image/*', null, true, $chunkSizeBytes);
$media->setFileSize(filesize($videoPath));
The rest of the code will be OAuth2. You can always use the framework I introduced as an answer to My zend application is unable to upload files on youtube
Is this possible to create a photo on user/page's timeline not by uploading said photo, but by providing a URL to an already uploaded image? My code so far is this:
$response = $fb->api ("/$page_id/photos", 'post', array (
'name' => $_description,
'source' => $_image_path
));
This results in OAuthException #324 "Requires upload file". Also, I'd like to photo to be immediately posted on the page's timeline - will it happen, or do I need to make a separate call for that?
You can switch parameter source for url, and give it a publicly reachable HTTP URL as value.
But be aware, this only works for photos not on Facebook already – feeding it the URL of a photo on Facebook will result in an error message saying that posting photos from their CDN is not possible.
I keep getting error code 34 (Sorry, this page does not exist) when attempting to make a post request to the statuses/filter method with the abraham twitteroauth class (https://github.com/abraham/twitteroauth). Following authentication (that's working fine) my request is simple:
$filter = $twitteroauth->post('statuses/filter',array('track' => 'seo'));
I have other calls working but even when I isolate this on a separate instance of the site, I'm only receiving the "Sorry, that page does not exist" error.
Any help would be appreciated.
TwitterOAuth does not currently support the Streaming APIs. You can try the method that #JohnC suggests but I don't know if it will actually work.
Phirehose is the PHP library I recommend for use with the Streaming APIs.
The statuses/filter call uses a different URL to many of the other API calls - using stream.twitter.com instead of api.twitter.com. The library you are using appears to be hardcoded to only use api.twitter.com, so this could be the source of your problem. You can either change the URL for that call:
$twitteroauth->host = "https://stream.twitter.com/1/";
$filter = $twitteroauth->post('statuses/filter',array('track' => 'seo'));
Or if you use the full URL it will override the default (probably the best way if you make multiple calls to the $twitteroauth class):
$filter = $twitteroauth->post('https://stream.twitter.com/1/statuses/filter.json',array('track' => 'seo'));
I have written an Application what posts Photos on a FanPage into a Specific Album long time ago.
Now I didn't used for a half year. Now I had to set up the Application again and grant the extended Permissions to the Fan Page (streamm_publish) again.
But now I've a Problem, I'm using the old REST API what now gives me the error: An unknown error ocurred with the error code 1.
Then I tried to post throught the Facebook Graph api.
I tried to make a call to the Api /pageid/albumid/photos what's not working(Unknown path components)
I tried to makea a call to /albumid_from_my_page/photos then the Photos were posted to my profile
I tried to upload it to /pageid/photos what is the same as the one above
But the code fpr the REST Api worked well, what's the problem there, and why the new Graph Api isn't working how she should?(BUG?)
To post a photo to an album, this is the code:
$post_data = array(
"message" => "My photo caption",
"source" => '#' . realpath($file)
);
$album_id = "XXXXX";
$facebook->api("/$album_id/photos", 'post', $post_data);
Now I suppose to interact with the page albums you need a page access_token added to your $post_data array, for this check this answer.
You need take ACCESS_TOKEN page...
try:
http://graph.facebook.com/me/accounts?access_token= GET THIS TOKEN USING GRAPH API... OR MAKE USING the getAccessToken()...
and will see all pages and aplications that u have, find just application for this case and COPY TOKEN... and damn!!!
It's possible to see this token thought GRAPH API EXPLORER...
regards.