Uploading video to YouTube using Dropbox public link? - php

I am using youtube ZEND gdata api to upload videos to My youtube account.But now I need to upload videos to YouTube which are stored in my DropBox account.I have public links or direct links for video files.Code I am using is:
<?php
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Gdata_App_Exception');
$developerKey = '******************';
$applicationId = '*********';
$clientId = '';
$video_title = 'test movie';
$video_description = 'test movie';
$video_category = 'Entertainment';
$video_tags = 'test,movie';
$path_of_uploaded_file = 'http://dl.dropbox.com/uhh/336/test.wmv';
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = '*****',
$password = '*****',
$service = 'youtube',
$client = null,
$source = '*******', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
$yt = new Zend_Gdata_YouTube($httpClient);
// create a new VideoEntry object
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
// create a new Zend_Gdata_App_MediaFileSource object
$filesource = $yt->newMediaFileSource($path_of_uploaded_file);
..
.
.
.
.
.?>
Error I am getting is:File to be uploaded at http://dl.dropbox.com/uhh/336/test.wmv does not exist or is not readable.
I don't why YouTube is throwing this error even though the URL is direct(Public) link. I am not getting what's wrong with my code and why it is not working.Please help :)

Just in case other are still looking for answers, I had a similar problem reading txt files with an app I wrote from Dropbox. I discovered that I wasn't using the right direct-link format. The correct link (for this threads example link) would be:
dl.dropboxusercontent.com/uhh/336/test.wmv
Just changing 'www' to 'dl' will work for web-browser as they handle redirects automatically. For apps and scripts you would have to integrate handling of redirects. Or just format the direct-link correctly.

It's impossible to answer this question definitively given the information provided, but we can narrow it down to a few possibilities. I would recommend you run down this quick debugging checklist:
If you copy/paste that exact link into your web browser, using the same credentials, are you able to download the video?
If not, then it's either a problem with the credentials or the URL itself.
If you are able to download it from the browser, then it means there's something wrong with your code or an issue with YouTube.
If you run through the above steps but you're still at an impasse, please post your results as a comment and we'll delve deeper.

The file you're uploading to YouTube must be on a local path.
Download the file locally using cURL
Set newMediaFileSource to the local file's path

In dropbox "get link" gives "link of dropbox page".
Try this.
Open up video page on dropbox.
right click on "download" and then "copy link location"
Hope this helps

Related

Vimeo API 2016 how to display list of users videos

I'm having trouble finding a simplified tutorial for using the Vimeo API I know I need to include vimeo.php and the following
include 'vimeo.php';
$vimeo = new phpVimeo('Client Identifier', 'Client Secrets');
$videos = $vimeo->call('vimeo.videos.getUploaded', array('user_id' => "user1877648"));
print_r($videos);
I've copied and pasted the fields I've used from the access Authentication in case that's where the issue is, I've also read that for simple calls to the API don't need access tokens?
I could really do with some pointers as to how I get a list of vimeo thumbs linking to the vimeo url from a specific user? I was using the older code and up until recently it worked well.
Dashron pointed you to all of the correct places to find the documentation needed to do what you are trying to do.
However, here is an example of how you would do it.
You need to download / clone the Vimeo PHP Library (found here: https://github.com/vimeo/vimeo.php).
Then go to Vimeo and create an app so you can acquire a client id and client secret (https://developer.vimeo.com/api/start).
Now that you have a client id, client secret, and the vimeo library, you can create a simple script to load all of the videos from a specific user. Here is an example:
<?php
// include the autoload file from the vimeo php library that was downloaded
include __DIR__ . '/vimeo/autoload.php';
// The client id and client secret needed to use the vimeo API
$clientId = "";
$clientSecret = "";
// when getting an auth token we need to provide the scope
// all possible scopes can be found here https://developer.vimeo.com/api/authentication#supported-scopes
$scope = "public";
// The id of the user
$userId = "alexbohs";
// initialize the vimeo library
$lib = new \Vimeo\Vimeo($clientId, $clientSecret);
// request an auth token (needed for all requests to the Vimeo API)
$token = $lib->clientCredentials($scope);
// set the token
$lib->setToken($token['body']['access_token']);
// request all of a user's videos, 50 per page
// a complete list of all endpoints can be found here https://developer.vimeo.com/api/endpoints
$videos = $lib->request("/users/$userId/videos", ['per_page' => 50]);
// loop through each video from the user
foreach($videos['body']['data'] as $video) {
// get the link to the video
$link = $video['link'];
// get the largest picture "thumb"
$pictures = $video['pictures']['sizes'];
$largestPicture = $pictures[count($pictures) - 1]['link'];
}
Keep in mind that the vimeo API returns "pages" of videos. So if the user has more than 50 videos per page you would need to do a request for each page by specifying the page number using "page" parameter (Change ['per_page' => 50] to ['per_page' => 50, 'page' => #].
This is the old, Advanced API. It is deprecated.
The new PHP library is here: https://github.com/vimeo/vimeo.php
The new API docs are here: https://developer.vimeo.com/api
The endpoint to retrieve all of your videos is https://api.vimeo.com/me/videos (https://developer.vimeo.com/api/endpoints/me#/videos)

How to browse files from projects google drive

i have created project in google console with service type credentials. I have downloaded p12 key file, and then wrote sample code for inserting file to test it:
<?php
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
require_once "google-api-php-client/src/contrib/Google_Oauth2Service.php";
$scopes = array('https://www.googleapis.com/auth/drive');
$accountEmail = 'SECRET';
$accountP12FilePath = './key.p12';
$key = file_get_contents($accountP12FilePath);
$auth = new Google_AssertionCredentials($accountEmail, $scopes, $key);
$client = new Google_Client();
$client->setUseObjects(true);
$client->setAssertionCredentials($auth);
$service = new Google_DriveService($client);
$file = new Google_DriveFile();
$file->setTitle('Test Title');
$file->setDescription('test description');
$parent = new Google_ParentReference();
$file->setParents(array($parent));
$createdFile = $service->files->insert($file, array(
'data' => 'test data',
'mimeType' => 'text/plain'
));
var_dump($createdFile);
?>
It dumps Google_DriveFile object with many urls. Some of them, like 'downloadUrl', returns 401 Unauthorized error. When I tried 'alternateLink' it showed google drive page with information that i need access, and buttons to request access and to switch account.
It also said that Im currently logged on my account, that was beeing used to create project, and that is visible on Permissions page of the project on the google console page.
How can I access drive that belongs to the project I used in the script ?
Finally found solution, it was missing permissions on file. Its worth to note that passing permission object to the $file object (before insertion) didn't work. I had to insert permission by passing already created file ID and permission object to the $service->permissions->insert method, just like that:
$permission = new Google_Permission();
$permission->setValue('PERSONAL.ACCOUNT#gmail.com');
$permission->setType('user');
$permission->setRole('writer');
$service->permissions->insert($createdFile->getId(), $permission);
Still I wasn't able to actually edit this file. When I opened file with URL
$createdFile->getAlternateLink();
Then I had to reopen that file with google docs. That copied file to my personal account and then I could only edit only that copy of a file, not a base file itself.
I dont know if there is a way to make that files truly editable, but I moved to the dropbox, as google drive API and its documentation SUX.

Download url not working in Google Drive API PHP

I am having issue with the Google Drive API, i was able to fetch the files using API But i can't download via this link. I guess, must some auth, but i have used refresh tokens to authenticate.Please see below for my code
$this->load->library('google-api-php-client/src/Google_Client');
include APPPATH . '/libraries/google-api-php-client/src/contrib/Google_DriveService.php';
// Library Files Configuration to get access token and Refresh Token
$client = new Google_Client();
$client->setAccessType('offline'); // default: offline
$client->setApplicationName('xxx'); //name of the application
$client->setClientId('yyyy'); //insert your client id
$client->setClientSecret('zzz'); //insert your client secret
$client->setScopes(array('https://www.googleapis.com/auth/drive'));
$service = new Google_DriveService($client);
$client->refreshToken($drive_data->refreshtoken);
$client->getAccessToken();
$parameters = array();
$files = $service->files->listFiles($parameters);
foreach ($files['items'] as $key => $items)
{
Download
}
Anybody knows how to get the download url with authentication?
This is having the answer:
(Java) Download URL not working
There seem to be some changes on v2 of GDrive, instead of using "downloadUrl" you may have to use "webContentLink" for getting the download link
To get downloadUrls, you need to get the metadata of a file. You can do so by using the get method. The method will return a File Resource representation. In this resource, there is a downloadUrl property. If you're able to access the files and get the URL already, then there should be no problem with your authentication setup. There could be permission issues where you may not have access to certain drive files, but if you receive no error for it, you should be fine there too. I am not particularly familiar with PHP, but perhaps you are not downloading it correctly? Here it seems to be done differently.
I also suggest that you check out the Drive PHP Quickstart App to use as a reference.
I have bumped into the same problem today and just found a solution for my case. I hope that this helps the one or another confused PHP coder out there who also does not get a downloadUrl. I assume that you are working with the examples of the v2 API, as seen on https://developers.google.com/drive/v2/reference.
First, I have altered the head to not only access the metadata but get full access (mind the DRIVE constant):
<?php
require 'vendor/autoload.php';
const DRIVE = "https://www.googleapis.com/auth/drive";
define('APPLICATION_NAME', 'MAGOS poller');
define('CREDENTIALS_PATH', 'credentials.json');
define('CLIENT_SECRET_PATH', 'client_secret.json');
define('SCOPES', implode(' ', array(Google_Service_Drive::DRIVE)));
Then I have deleted my credentials file (credentials.json) and reran the script so it authenticated once more against gDrive and recreated the credentials file. After that
$downloadUrl = $file->getDownloadUrl();
finally worked like a charm.

Text gets auto Tweeted while Media (image) does not

I am using this ridiculously simple script to auto Tweet on behalf of a user.
$image = 'test.jpg';
// Insert your keys/tokens
$consumerKey = 'xxx';
$consumerSecret = 'xxx';
$OAuthToken = 'xxx';
$OAuthSecret = 'xxx';
// Full path to twitterOAuth.php (change OAuth to your own path)
require_once('connect/twitter/twitteroauth.php');
$params = array(
'status' => $_REQUEST['content'],
'media[]' => '#{$image}'
);
// create new instance
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $OAuthToken, $OAuthSecret);
// Send tweet
$tweet->post('statuses/update', $params);
Upon executing this code, text gets Tweeted on my twitter account however the image does not. I have been previously advised to only attempt tweeting local files and I was advised this is the proper way to specify the media[].
Why isnt this posting the image while its posting the text to twitter?
You need to call statuses/update_with_media - not statuses/update (which you are currently using).
For more information, please read the documentation.
I guess you are using the Abraham Library. It won't work for Tweet with Media. I was in the position last month & this library helped me. Just Download & Copy the twitteroauth folder from the extracted folder & paste it in your project folder by renaming it into twitteroauth1. Why because, there might a folder twitteroauth or files twitteroauth.php & 'oAuth.php` already present in the Abraham Library.
Now, you just want to edit the include or require_once as
require_once('twitteroauth1/twitteroauth.php');
The new twitteroauth.php will help to tweet with media. Also, in your code, it's not
$tweet->post('statuses/update', $params);
Instead, it should be,
$tweet->post('statuses/update_with_media', $params);

What are the prerequisites for Facebook stream.publish?

I'm wondering if someone would help me troubleshoot my test for stream.publish. I thought I had all the right pieces. Here's the code:
<?php
require_once 'facebook.php';
$appapikey = 'xxxxxxx';
$appsecret = 'xxxxxxx';
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();
$message = "Will this status show up and allow me to dominate the world?!";
$uid = $user_id;
echo $uid;
$facebook->api_client->stream_publish($message,$uid);
What I'm expecting is my status to change to $message's content. What happens instead is that my UID is echo'd, and then it throws a 500 error. I've allowed publish_stream as well as offline_access (verified in my app settings, via my profile), the the API key hooks this small bit of code to my app. What other pieces do I need to make this simple example work? I'm finding the FB documentation a little hard to put together.
-- The include is the official PHP Facebook library
stream_publish() takes more than two arguments:
stream_publish($message, $attachment = null,
$action_links = null, $target_id = null,
$uid = null)
Where $target_id is the user or page you're publishing to and $uid is the user or page who is doing the publishing - and which defaults to your session id. To be completely explicit about this, I think you need to try
<?php
require_once 'facebook.php';
$appapikey = 'xxxxxxx';
$appsecret = 'xxxxxxx';
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();
$message = "Will this status show up and allow me to dominate the world?!";
echo $user_id;
$facebook->api_client->stream_publish($message,null,null,$user_id,$user_id);
An alternate form might be:
$app_id = 'xxxxxxx';
$facebook->api_client->stream_publish($message,null,null,$user_id,$app_id);
This one works in 2011! I had the same problem. Most of the tuts seem to be out of date thanks to Facebook changes. I eventually found a way that worked and did a quick blog article about it here:
http://facebookanswers.co.uk/?p=214
There's also a screen shot to show you what the result is. Make sure you also see the blog post about authentication though.
Remove the $uid variable as it is not needed for publishing. Refer to this wiki entry for more info
$stream_post_id = $facebook->api_client->stream_publish($message);
//returns $post_id to use if you want to revert the creation.
If you are trying to use streamPublish with an iFrame application, here is an awesome step-by-step tutorial that doesn't have to use getAppPermissions:
http://thetechnicalexperience.blogspot.com/2010/02/how-to-use-fbconnectstreampublish.html

Categories