I am trying to upload video using my developer key to a youtube channel that is owned by my google account.
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient =
Zend_Gdata_ClientLogin::getHttpClient(
$username = 'username',
$password = 'pass',
$service = 'youtube',
$client = null,
$source = 'mysource', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$developerKey = 'key';
$applicationId = 'Video Upload';
$clientId = 'Video Uploader v1';
However when i try to upload to that channel it gives me "write-access" error even though this channel is owned by me.
I can manage this youtube channel easily using "switch account" of youtube. but when it comes to upload using the API i get write-access error.
I use upload url like this
http://uploads.gdata.youtube.com/feeds/api/users/CHANNELUSERNAME/uploads
Any idea how to fix this ?
This blog will give you the right information on how to manage multiple channels via API.
Related
I want to make functionality for users to upload video on my channel without authentication (if needed). IS it possible ?
Please help me .
Thanks
OM
Yes Omprakash,it is possible
You will need Google APIs Client Library for PHP.
You will also need to create a project on
https://console.developers.google.com/ and get credentials(i.e
client secret & client id).
Finally,you will need to generate access token for specific channel.
Please take a look at this link
(https://youtube-eng.googleblog.com/2013/06/google-page-identities-and-youtube-api_24.html)
to generate access token.
Once you have all these things ready with you,you can use ready made
example code available in Google APIs Client Library for PHP to upload
video on YouTube.
Note: This is not in detail process.It is not possible to explain all of the process in detail on stack-overflow. But, once you get close to solution,you can re-post or put comment for further assistance.
This is example code to upload video on YouTube. Hope, it will help you
/*include google libraries */
require_once '../api/src/Google/autoload.php';
require_once '../api/src/Google/Client.php';
require_once '../api/src/Google/Service/YouTube.php';
$application_name = 'Your application/project name created on google developer console';
$client_secret = 'Your client secret';
$client_id = 'Your client id';
$scope = array('https://www.googleapis.com/auth/youtube.upload', 'https://www.googleapis.com/auth/youtube', 'https://www.googleapis.com/auth/youtubepartner');
try{
$key = file_get_contents('the_key.txt'); //it stores access token obtained in step 3
$videoPath = 'video path on your server goes here';
$videoTitle = 'video title';
$videoDescription = 'video description';
$videoCategory = "22"; //please take a look at youtube video categories for videoCategory.Not so important for our example
$videoTags = array('tag1', 'tag2','tag3');
// Client init
$client = new Google_Client();
$client->setApplicationName($application_name);
$client->setClientId($client_id);
$client->setAccessType('offline');
$client->setAccessToken($key);
$client->setScopes($scope);
$client->setClientSecret($client_secret);
if ($client->getAccessToken()) {
/**
* Check to see if our access token has expired. If so, get a new one and save it to file for future use.
*/
if($client->isAccessTokenExpired()) {
$newToken = json_decode($client->getAccessToken());
$client->refreshToken($newToken->refresh_token);
file_put_contents('the_key.txt', $client->getAccessToken());
}
$youtube = new Google_Service_YouTube($client);
// Create a snipet with title, description, tags and category id
$snippet = new Google_Service_YouTube_VideoSnippet();
$snippet->setTitle($videoTitle);
$snippet->setDescription($videoDescription);
$snippet->setCategoryId($videoCategory);
$snippet->setTags($videoTags);
// Create a video status with privacy status. Options are "public", "private" and "unlisted".
$status = new Google_Service_YouTube_VideoStatus();
$status->setPrivacyStatus('public');
// Create a YouTube video with snippet and status
$video = new Google_Service_YouTube_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
// Size of each chunk of data in bytes. Setting it higher leads faster upload (less chunks,
// for reliable connections). Setting it lower leads better recovery (fine-grained chunks)
$chunkSizeBytes = 1 * 1024 * 1024;
// Setting the defer flag to true tells the client to return a request which can be called
// with ->execute(); instead of making the API call immediately.
$client->setDefer(true);
// Create a request for the API's videos.insert method to create and upload the video.
$insertRequest = $youtube->videos->insert("status,snippet", $video);
// Create a MediaFileUpload object for resumable uploads.
$media = new Google_Http_MediaFileUpload(
$client,
$insertRequest,
'video/*',
null,
true,
$chunkSizeBytes
);
$media->setFileSize(filesize($videoPath));
// Read the media file and upload it chunk by chunk.
$status = false;
$handle = fopen($videoPath, "rb");
while (!$status && !feof($handle)) {
$chunk = fread($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
fclose($handle);
/**
* Video has successfully been upload, now lets perform some cleanup functions for this video
*/
if ($status->status['uploadStatus'] == 'uploaded') {
$youtube_id = $status->id; //you got here youtube video id
} else {
// handle failere here
}
// If you want to make other calls after the file upload, set setDefer back to false
$client->setDefer(true);
} else{
// #TODO Log error
echo 'Problems creating the client';
}
} catch(Google_Service_Exception $e) {
echo "\r\n Caught Google service Exception ".$e->getCode(). " message is ".$e->getMessage();
echo "\r\n Stack trace is ".$e->getTraceAsString();
} catch (Exception $e) {
echo "\r\n Caught Google service Exception ".$e->getCode(). " message is ".$e->getMessage();
echo "\r\n Stack trace is ".$e->getTraceAsString();
}
Hi all i developed an application for posting tweet using PHp with twitter api 1.1. But that option is only working for me only. If any one authenticated and try to send tweet using that. It's posting tweet on my wall.
How to make this generalized for anyone.
YOUR_CONSUMER_KEY = 'xxxxxxxxxxxxxx';
YOUR_CONSUMER_SECRET = 'xxxx';
$twitteroauth = new TwitterOAuth(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET);
// Requesting authentication tokens, the parameter is the URL we will be redirected to
$request_token = $twitteroauth->getRequestToken('http://xxxx/xxxx/getTwitterData.php');
//print_r($request_token);
$twitteroauth = new TwitterOAuth(YOUR_CONSUMER_KEY, YOUR_CONSUMER_SECRET, $request_token['oauth_token'], $request_token['oauth_token_secret']);
$tmessage = $_POST['message'];
$content = $twitteroauth->post('statuses/update', array('status' => $tmessage));
it's posting tweets on your wall because you're using access token and secret of the app, or you're the authenticated user. You need to log in the user you want to post for, get their access token and secret, then use consumer key, secret, user access token and user access secret to post on their behalf.
It's a bit unclear what you're trying to do, but here's a sample post action with Abraham William's library, which you're using:
require_once('twitteroauth.php');
$key = "***";
$secret = "***";
$token = "***";
$token_secret = "***";
$connection = new TwitterOAuth($key, $secret, $token, $token_secret);
$message = "whatever";
$status = $connection->post($message);
$response= $connection->http_code;
if($response !=200){
echo "ERROR";
}else{
echo "life is good";
}
I have a code, where people can post messages on the app's wall via my app
$consumerKey = '';
$consumerSecret = '';
$accessToken = '';
$accessTokenSecret = '';
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
$tweetMessage = $_POST['message'];
if(strlen($tweetMessage)<=140)
{
$tweet->post('statuses/update', array('status' => $tweetMessage));
$day = date('Y-m-d H:i:s');
mysql_query("INSERT INTO users (message,data,social) VALUES ('".$_POST['message']."','".$day."','tw')");
}
how can I make the script to post messages from users on their own walls via my app ?
is it possible?
thank you!
Actually, now that I think of it, what you probably want here is not a Twitter application at all. Since you want your visitors to post messages themselves, the correct way to do this is by using Twitter Web Intents.
I'm trying to get a youtube video from the $username with $tags:
$tags='detskij-sad-198';
require_once('Zend/Loader.php');
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
$authenticationURL = 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = 'Schoolkharkovua',
$password = '*****',
$service = 'youtube',
$client = null,
$source = '*****',
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$devkey = '*****';
$yt = new Zend_Gdata_YouTube($httpClient, '', '', $devkey);
$yt->setMajorProtocolVersion(2);
$query = $yt->newVideoQuery();
$query->setMaxResults(4);
$query->setVideoQuery($tags); // also i tried $query->category = $tags;
$query->setAuthor($username);
$videoFeed = $yt->getVideoFeed($query->getQueryUrl(2));
$videoFeed returns no entry, although I know that the $username has a video with $tags and this code to work until mid-March
If I do query only by the $username or by $tags - I get the result.
What am I doing wrong?
PS. http://gdata.youtube.com/demo/index.html return empty video feed too if I trying query by "Keywords" and "Author name" simultaneously
Hhhhhmmmmm.... It seems that "google" no longer get the symbols "-" in tags
But
echo 'Tags: ' . implode(", ", $videoEntry->getVideoTags());
still emty, youtube api don't return video tags!
Guys help me get video tags from my video channel, please!
You need to authenticate your connection, YT returns an empty media$keywords object now (as of last Aug).
https://developers.google.com/youtube/2.0/developers_guide_php#Authentication
and here's their blog post about it...
http://apiblog.youtube.com/2012/08/video-tags-just-for-uploaders.html
I am using the "youtube api" for PHP library, ie zend.
My goal is to set the description, ie what you see when you open the channel of a user in the textbox at the right.
What I did.
function anmelden_yt($name,$passwort)
{
$yt_source = 'sou'; //name of application (can be anything)
$yt_api_key = 'ak';
$yt = null;
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = $name,
$password = $passwort,
$service = 'youtube',
$client = null,
$source = $yt_source, // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
return new Zend_Gdata_YouTube($httpClient, $yt_source, NULL, $yt_api_key);
}
$yt = anmelden_yt('name','pw');
$yt->setMajorProtocolVersion(2);
$userProfileEntry = $yt->getUserProfile('name');
$userProfileEntry->setAboutMe('test');
$userProfileEntry->setContent('test');
$userProfileEntry->setSummary('test');
Nothing changed.
Those fields are no longer exposed via the API. They also don't correspond to the channel description display that you're referring to. There currently isn't a way to set that channel description via the API.