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)
Related
I've been struggling with this problem for a while.
I'm trying to upload videos to Youtube using the Youtube V3 API. I've added the correct scopes to the OAuth Consent screen and the project was approved recently (went through the whole audit thingie), but the videos are still marked as private when they are uploaded.
I've tested with different video files on different accounts.
I've created new API keys, even restricted the keys and still no success.
I'm using the latest version of the Google APIs Client Library for PHP.
Any help would be appreciated. I don't even know how to contact Google for support on this one.
Edit: This is the code snippet that handles video upload
//Code that retrieves the api auth data is not included
//Also not included is the code that prepares the video path, title, description and category
$google_client = new \Google_Client();
// Offline because we need to get refresh token
$google_client->setAccessType('offline');
// Name of the google application
$google_client->setApplicationName($appName);
// Set the client_id
$google_client->setClientId($clientId);
// Set the client_secret
$google_client->setClientSecret($clientSecret);
// Redirects to same url
$google_client->setRedirectUri($scriptUri);
// Set the api key
$google_client->setDeveloperKey($apiKey);
// Load required scopes
$google_client->setScopes(array(
'https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/userinfo.profile'
));
// Refresh token
$google_client->refreshToken($refresh_token);
// Get access token
$new_access_token = $google_client->getAccessToken();
// Set access token
$google_client->setAccessToken($new_access_token);
// Define service object for making API requests.
$youtube_service = new \Google_Service_YouTube($google_client);
// Define the $youtube_video object, which will be uploaded as the request body.
$youtube_video = new \Google_Service_YouTube_Video();
// Add 'snippet' object to the $youtube_video object.
$video_snippet = new \Google_Service_YouTube_VideoSnippet();
// Add category, title, description
$video_snippet->setCategoryId($video_category);
$video_snippet->setTitle($video_title);
$video_snippet->setDescription($video_description);
$youtube_video->setSnippet($video_snippet);
// Add 'status' object to the $youtube_video object.
$video_status = new \Google_Service_YouTube_VideoStatus();
$video_status->setPrivacyStatus('public');
$youtube_video->setStatus($video_status);
//Get MIME
$file_info = finfo_open(FILEINFO_MIME_TYPE);
$mime_type = finfo_file($file_info, $video_path);
$upload = $youtube_service->videos->insert('snippet,status', $youtube_video, array(
'data' => file_get_contents($video_path),
'mimeType' => $mime_type,
'uploadType' => 'multipart'
));
i'm trying to use, Vimeo php api to play a private video using his id. I have created an account pro on vimeo, i have created a Vimeo app, i have created a token with public and private scope. The php code i use is this:
require("../Vimeo PHP path/autoload.php");
use Vimeo\Vimeo;
$client_id = "*****"; //your Vimeo number here
$client_secret = "*****"; //your Vimeo number here
$access_token = "*****"; //your Vimeo number here
$vimeo = new Vimeo($client_id, $client_secret, $access_token);
$videos = $vimeo->request("/videos/$video_id");
print_r($videos);
It works (i have take this code here).
Launching the page i can see my video inside the print_r($videos), but is still private, i see the black screen "Private video, log in to watch". Why? If i pass a client_id, a token and a secret i can't see a private video? Only users that are signed in my site can see my vimeo videos, but i wanna embed this video without force my users to create a vimeo account. How i can achive this result with private videos?
The video that is visible in that print_r is the embed video. At this step, the site respects your embed settings, followed by your on site privacy settings.
If you want to use the embed, you must set your video's privacy to "Hide from vimeo" (or disabled in the API), and then set your embed privacy to anything but "Nowhere"
If you want to use your own player, or a mobile device, you want to use one of the urls in the files key of the JSON response.
I'm trying to access users playlist tracks by using the client credentials flow.
Spotify getting playlist documentation: https://developer.spotify.com/web-api/get-playlists-tracks/
Spotify getting client credentials documentation: https://developer.spotify.com/web-api/authorization-guide/
First question, is it possible to get a users playlist tracks using client credentials flow? I'm using this flow since I'm unable to pop up a login box for the user to login.
Secondly, I've tried using https://github.com/jwilsson/spotify-web-api-php client credentials flow (Docs: http://jwilsson.github.io/spotify-web-api-php/authorization.html) by practically copying the code at the bottom of that page:
<?php
include('vendor/autoload.php');
$session = new SpotifyWebAPI\Session('Tobys client id', 'Tobys secret', 'http://localhost/callback');
// Request a access token with optional scopes
$scopes = array(
'playlist-read-private',
'user-read-private'
);
$session->requestCredentialsToken($scopes);
$accessToken = $session->getAccessToken(); // We're good to go!
// Set the code on the API wrapper
$api->setAccessToken($accessToken);
$playlists = $api->getUserPlaylists('USER_ID', array(
'limit' => 5
));
foreach ($playlists->items as $playlist) {
echo '' . $playlist->name . ' <br>';
}
This gives me Notice: Undefined variable: api in /var/www/html/dev/testing.php on line 16
I've also tried creating the API variable using $api = new SpotifyWebAPI\SpotifyWebAPI(); but this says I need user information/ tokens.
Thanks.
First question, is it possible to get a users playlist tracks using
client credentials flow?
Yes, retrieving tracks for a playlist doesn't require user authentication as part of the access token.
I've also tried creating the API variable using $api = new
SpotifyWebAPI\SpotifyWebAPI(); but this says I need user information/
tokens.
Looking at the code (Session class, SpotifyWebapi class), it does look like you should set this up by doing
$api = new SpotifyWebAPI\SpotifyWebAPI();
$session = new SpotifyWebAPI\Session($clientId, $clientSecret, $redirectUri);
$api->setAccessToken($session->getAccessToken());
When that's set up you should be good to use the getUserPlaylists method like you're doing in your example code.
I am trying to upload a video to youtube using client library v3.
The v3 library is experimental and does not have much documentation
(samples provided does not include youtube)
I have properly authenticated user with oauth 2.0. And when I have access token, I am trying with this code.
if ($client->getAccessToken()) {
$snippet = new Google_VideoSnippet();
$snippet -> setTitle = "Demo title";
$snippet -> setDescriptio = "Demo descrition";
$snippet -> setTags = array("tag1","tag2");
$snippet -> setMimeType = 'video/quicktime';
$video = new Google_Video();
$video -> setSnippet($snippet);
// Not sure what to do now....
$_SESSION['access_token'] = $client->getAccessToken();
}
From the docs,
I need to supply a part parameter
The part parameter serves two purposes in this operation. It identifies the properties that the write operation will set as well as the properties that the API response will include.
The part names that you can include in the parameter value are snippet, contentDetails, player, statistics, status, and topicDetails. However, not all of those parts contain properties that can be set when setting or updating a video's metadata. For example, the statistics object encapsulates statistics that YouTube calculates for a video and does not contain values that you can set or modify. If the parameter value specifies a part that does not contain mutable values, that part will still be included in the API response.
But it lacks documentation except a python example which I am not able to understand.
(the example is at the bottom of the link , I provided)
Please, dont give example/links to zend library, it uses auth-sub which I dont want.
I want to use oauth 2.0.
The code to upload a video looks like this.
$youtubeService->videos->insert($part, Google_Video $postBody, $optParams = array());
'part' is what you want the request to return. In this case that could just be status, which return information about the status of the upload.
The release of the Google PHP client library might be old, so you'll want to checkout the source at https://code.google.com/p/google-api-php-client/
Using Facebook's PHP SDK, I was able to get Facebook login working pretty quickly on my website. They simply set a $user variable that can be accessed very easily.
I've had no such luck trying to get Twitter's OAuth login working... quite frankly, their github material is confusing and useless for someone that's relatively new to PHP and web design, not to mention that many of the unofficial examples I've tried working through are just as confusing or are outdated.
I really need some help getting Twitter login working--I mean just a basic example where I click the login button, I authorize my app, and it redirects to a page where it displays the name of the logged in user.
I really appreciate your help.
EDIT I'm aware of the existence of abraham's twitter oauth but it provides close to no instructions whatsoever to get his stuff working.
this one is the basic example of getting the url for authorization and then fetching the user basic info when once u get back from twitter
<?php
session_start();
//add autoload note:do check your file paths in autoload.php
require "ret/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
//this code will run when returned from twiter after authentication
if(isset($_SESSION['oauth_token'])){
$oauth_token=$_SESSION['oauth_token'];unset($_SESSION['oauth_token']);
$consumer_key = 'your consumer key';
$consumer_secret = 'your secret key';
$connection = new TwitterOAuth($consumer_key, $consumer_secret);
//necessary to get access token other wise u will not have permision to get user info
$params=array("oauth_verifier" => $_GET['oauth_verifier'],"oauth_token"=>$_GET['oauth_token']);
$access_token = $connection->oauth("oauth/access_token", $params);
//now again create new instance using updated return oauth_token and oauth_token_secret because old one expired if u dont u this u will also get token expired error
$connection = new TwitterOAuth($consumer_key, $consumer_secret,
$access_token['oauth_token'],$access_token['oauth_token_secret']);
$content = $connection->get("account/verify_credentials");
print_r($content);
}
else{
// main startup code
$consumer_key = 'your consumer key';
$consumer_secret = 'your secret key';
//this code will return your valid url which u can use in iframe src to popup or can directly view the page as its happening in this example
$connection = new TwitterOAuth($consumer_key, $consumer_secret);
$temporary_credentials = $connection->oauth('oauth/request_token', array("oauth_callback" =>'http://dev.crm.alifca.com/twitter/index.php'));
$_SESSION['oauth_token']=$temporary_credentials['oauth_token']; $_SESSION['oauth_token_secret']=$temporary_credentials['oauth_token_secret'];$url = $connection->url("oauth/authorize", array("oauth_token" => $temporary_credentials['oauth_token']));
// REDIRECTING TO THE URL
header('Location: ' . $url);
}
?>
I just tried abraham's twitteroauth from github and it seems to work fine for me. This is what I did
git clone https://github.com/abraham/twitteroauth.git
Upload this into your webhost with domain, say, www.example.com
Go to Twitter Apps and register your application. The changes that you need are (assuming that you will use abraham's twitteroauth example hosted at http://www.example.com/twitteroauth)
a) Application Website will be http://www.example.com/twitteroauth
b) Application type will be browser
c) Callback url is http://www.example.com/twitteroauth/callback.php (Callback.php is included in the git source)
Once you do this, you will get the CONSUMER_KEY and CONSUMER_SECRET which you can update in the config.php from the twitteroauth distribution. Also set the callback to be the same as http://www.example.com/twitteroauth/callback.php
Thats it. If you now navigate to http://www.example.com/twitteroauth, you will get a "Signin with Twitter", that will take you to Twitter , authorize the request and get you back to the index.php page.
EDIT:
Example will not work but do not worry. Follow the above steps and upload to server.
Make sure you rename the file from github repository i.e. config-sample.php->config.php
if you want to see a working sample, find it here
Here are some OAuth 1.0A PHP libraries with examples:
tmhOAuth
Oauth-php
Twitter async
Twitter async provides documentation on how to simply sign in a user as you asked for.
Here is the step by step guide to integrate Twitter OAuth API to Web-application using PHP. Please following tutorial.
http://www.smarttutorials.net/sign-in-with-twitter-oauth-api-using-php/
You need to create Twitter App First By going thorugh following URL
https://apps.twitter.com/
Then you need to provide necessary information for the twitter app. Once your provided all the information and then save it. You will get Twitter application Consumer Key and Consumer secret.
Please download the source file from above link, and just replace TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET and TWITTER_OAUTH_CALLBACK with your Consumer Key (API Key), Consumer Secret (API Secret) and callback URL. Then upload this to your server. Now it will work successfully.
Abraham's Twitteroauth has a working demo here:
https://github.com/abraham/twitteroauth-demo
Following the steps in the demo readme worked for me. In order to run composer on macOS I had to do this after installing it: mv composer.phar /usr/local/bin/composer
IMO the demo could be a lot simpler and should be included in the main twitteroauth repo.
I recently had to post new tweets to Twitter via PHP using V2 of their API but couldn’t find any decent examples online that didn’t use V1 or V1.1. I eventually figured it out using the great package TwitterOAuth.
Install this package via composer require abraham/twitteroauth first (or manually) and visit developer.twitter.com, create a new app to get the credentials needed to use the API (see below). Then you can post a tweet based on the code below.
use Abraham\TwitterOAuth\TwitterOAuth;
// Connect
$connection = new TwitterOAuth($twitterConsumerKey, // Your API key
$twitterConsumerSecret, // Your API secret key
$twitterOauthAccessToken, // From your app created at https://developer.twitter.com/
$twitterOauthAccessTokenSecret); // From your app created at https://developer.twitter.com/
// Set API version to 2
$connection->setApiVersion('2');
// POST the tweet; the third parameter must be set to true so it is sent as JSON
// See https://developer.twitter.com/en/docs/twitter-api/tweets/manage-tweets/api-reference/post-tweets for all options
$response = $connection->post('tweets', ['text' => 'Hello Twitter'], true);
if (isset($response['title']) && $response['title'] == 'Unauthorized') {
// Handle error
} else {
var_dump($response);
/*
object(stdClass)#404 (1) {
["data"]=>
object(stdClass)#397 (2) {
["id"]=>
string(19) "0123456789012345678"
["text"]=>
string(13) "Hello Twitter"
}
}
*/
}