How to delete a video using the youtube API v3 and PHP - php

Just wondering how I would delete a video from YouTube using v3 of the API using the official Google PHP library.
I see this here:
Deleting a video from a playlist with YouTube Data API v3
$youtubeService = new Google_YouTubeService($client);
$playlistItems = $youtubeService->playlistItems;
$deleteVid = $playlistItems->delete($videocode);
Not sure if this is correct - does this work if the video is not in a playlist?
I also have the code for v2 of the API
Deleting YouTube videos using Zend/PHP
$videoEntryToDelete = $yt->getVideoEntry($videoId, null, true);
$yt->delete($videoEntryToDelete);
But rather use v3

For those looking for the answer it was this:
$youtube = new Google_Service_YouTube($client);
...
//do your authoraisation stuff + getting access token etc
...
$youtube->videos->delete('<Your Video ID>');
Hope that helps!

Related

How to access google photos using api in php?

I want to fetch all the photos on Google photos on my web site using php.
Is it possible?. I know Picasa Web Albums Data API deprecated. I have got try it from Picasa. but i am not able to download library from https://developers.google.com/gdata/articles/php_client_lib.
There is currently no Google Photos API. The only thing available is Picasa. You may be able to upload the pictures to your google drive account and display them on your website that way. However your probably going to have to set the pictures to public.
There is an API now for Google photo's.
But I've not been successfull in making it work myself
https://developers.google.com/photos/
I am trying to do the same thing, so far, I setup the api:
From Google Console API --> enabled the photos library api.
Following this example : https://github.com/google/google-api-php-client/blob/master/examples/simple-query.php
I managed to setup the api with the following code :
include_once __DIR__ . '/vendor/autoload.php';
include_once 'base.php';
# create client
$client = new Google_Client();
$client -> setApplicationName("Client_Library_examples");
if(!$apiKey = getApiKey()) {
echo missingApiKeyWarning();
}
$client -> setDeveloperKey($apiKey);
The autoload and base.php files were copied from the mentioned link. I copied my api to a file .apiKey.
Up to this point, the code works fine, the example in the previous link explains how to create a new google service for e-books. There must be a similar thing for google photos but couldn't find any yet.
I found the following but I am not getting anything with the echo :
$response = file_get_contents('https://photoslibrary.googleapis.com/v1/albums');
$response = json_decode($response);
echo $response

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 get twitter new followers by using API in php?

i need to get twitter new followers using twitter API. I am able to get total followers but not able to get NEW followers.
$obj = new TwitterOAuth($keys['AppKey'], $keys['SecretKey'],$sKey2,$sKey3);
$detail = $obj->get('account/verify_credentials');
$return=$return+$detail->followers_count;
How to get new followers not total followers?
For authorized users you can use Twitter Stream API for track new followers:
https://dev.twitter.com/streaming/overview/messages-types#Events_event
I use it with C# library https://github.com/linvi/tweetinvi
and code is very simple:
Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
var stream = Stream.CreateUserStream();
stream.FollowedByUser += (sender, args) =>
{
Console.WriteLine("You have been followed by " + args.User);
};
stream.StartStream();
I think there is same library for php too. Or you can try use Twitter Stream API from php directly

Youtube API Thumbnails:set

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

How to get all the videos link from a youtube playlist .

i am using zend framework for retrieving youtube video information ,
I need a way To get all the video links inside a playlist, the playlist Id is known .
is there any method for retrieving the above information ?
thanks
You'll need to use the YouTube Data API:
$yt = new Zend_Gdata_YouTube();
$feedUrl = $playlistEntry->getPlaylistVideoFeedUrl();
$playlistVideoFeed = $yt->getPlaylistVideoFeed($feedUrl);
You'll need to authenticate if it's a private playlist, but not if it's public.
Read more on the relevant Zend Framework Manual and Google Reference Guide pages.

Categories