PUT / Soundcloud API with cURL - php

I'm using this code to get a user but how do it "like" a track via a PUT request in cURL & PHP?
// build our API URL
$url = "http://api.soundcloud.com/resolve.json?"
. "url=http://soundcloud.com/"
. "USERNAME-HERE"
. "&client_id=CLIENT-ID-HERE";
// Grab the contents of the URL
$user_json = file_get_contents($url);
// Decode the JSON to a PHP Object
$user = json_decode($user_json);
// Print out the User ID
echo $user->id;

See SoundCloud API Documentation - /users.
You can favourite a track for a user with a PUT request in the following format:
/users/{user_id}/favorites/{track_id}
If you don't know how to make the cURL request, Google it - there are hundreds of tutorials and answers on StackOverflow. Here is one example:
Querying API through Curl/PHP

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)

Getting Twitch followers using Twitch API in PHP

What I'm trying to do is make a twitch follower alert in PHP. The only stuff so far that I have gotten done is find out where to get the info from. I need assistance decoding the info, and then getting the user name and setting it to a string. The place for the recent followers is: https://api.twitch.tv/kraken/channels/trippednw/follows/?limit=1
The data Twitch's API gives you is in JSON format (JavaScript Object Notation). You can decode it using json_decode($data, true). This gives you an associative array with the required fields. For example, to get the name of the user who most recently followed:
json_decode($twitch_data, true)['follows'][0]['user']['name']
Update:
Here's a more detailed answer. First, you're going to have to get the data from the Twitch API via a get request using file_get_contents(). Then, you parse the resulting JSON using the method described above and echo that out onto the page. Here's the full code:
<?php
$api_url = 'https://api.twitch.tv/kraken/channels/trippednw/follows/?limit=1';
$api_data = file_get_contents($api_url);
$last_follow = json_decode($api_data, true)['follows'][0]['user']['name'];
echo "The last user to follow <strong>trippednw</strong> on Twitch is <strong>" . $last_follow . "</strong>.";
?>

Get my own full profile with LinkedIn API

For testing purposes, I'd like to get my own full profile datas from LinkedIn API.
So far my code looks like this :
// Fill the keys and secrets you retrieved after registering your app
$oauth = new OAuth("APIKEY", "SECRETKEY");
$oauth->setToken("Token OAuth", "Secret User OAuth");
$oauth->disableSSLChecks();
$params = array();
$headers = array();
$method = OAUTH_HTTP_METHOD_GET;
// Specify LinkedIn API endpoint to retrieve your own profile
$url = "https://api.linkedin.com/v1/people/~:(first-name,last-name,headline,location:(name),skills:(name),educations:(id,school-name,field-of-study))?format=json";
// By default, the LinkedIn API responses are in XML format. If you prefer JSON, simply specify the format in your call
// $url = "https://api.linkedin.com/v1/people/~?format=json";
// Make call to LinkedIn to retrieve your own profile
$oauth->fetch($url, $params, $method, $headers);
$oProfile = json_decode($oauth->getLastResponse());
var_dump($oProfile);
Although I am getting basic profile informations (firstName,headline etc...) but when it comes to full profile informations I get an object with '...' as value everytime, although the informations exist.
I have r_fullprofile ticked in my LinkedIn app interface, so I don't know what I have to do to get these values.
I tried your query with my own account. It looks you issue is with the skills field.
You can see in the LinkedIn API documentation that skills are made up of a skill, and each skill has a name. If you only want the name returned the proper way to ask for it is
skills:(skill:(name)), whereas your request asks for skills:(name).
Here is an updated request for you:
GET https://api.linkedin.com/v1/people/~:(first-name,last-name,headline,location:(name),skills:(skill:(name)),educations:(id,school-name,field-of-study))?format=json

Getting JSON data from Twitter using ID in PHP

I have a following script which helps me getting data in json format from a particular Facebook ID.
Here's the code
if($recipy_info[0]['social_media']=='facebook')
{
$pageContent = file_get_contents('https://graph.facebook.com/'.$recipy_info[0]['post_userid'].'?fields=id,name,picture,birthday');
$parsedJson = json_decode($pageContent);
//$facebook_info= https://graph.facebook.com/100003384367738?fields=id,name,picture,birthday
}
Now the issue is that I want to have a similar work for Twitter, I don't have screen name, all I have is just the id 1897279429.
I have a url https://api.twitter.com/1.1/trends/1897279429.json, but it gives me this error:
{"errors":[{"message":"Bad Authentication data","code":215}]}
How can I sort my problem?
I want to get JSON data from the id I have.
Since API 1.1 you are required to authenticate first before you can get the public tweets from a user. Please take a look at the API documentation here: https://dev.twitter.com/docs

Get wall feed from a public Facebook page using Graph API - is it really this complex?

I have started off by reading Displaying Facebook posts to non-Facebook users which is of some use but I cannot believe it is this difficult to get a public feed from Facebook.
The page I want a feed from is public, you do not need to be logged into get to it.
Am I right in presuming that I need an access_token to get to this information, attempting to access the URL without results in an OAuth error.
So the flow should be like this (massively, overly complex):
Authenticate using a user (what if the user isn't on Facebook?)
Some complex OAuth nonsense - just to read the feed, I do not even want a like button or post to wall functionality
Get the feed using a PHP request to the correct URL with the user's access_token
Render the feed
Assuming the user isn't on Facebook, what do you do, use a generic app to get the feed?
Hardcode an auth request to Facebook using my generic app's ID and secret
Some complex OAuth nonsense
Get the feed using a PHP request to the correct URL with the app's access_token
Render the feed
Oh no, the auth has expired, re-auth and capture this new access_token for use in future requests.
This seems really complex for no reason other than Facebook wants to know EVERYTHING that is going on, it'd be easier to do a cURL and scrape the content from the public URL using XPath.
Any help on this would be great.
Thanks,
Jake
EDIT
An edit to show this is not an exact duplicate.
I had this working with an access_token in place, but now it fails, the token has expired and I can no longer use it to obtain information from the public wall.
I attempted to extend the expiration date of this token using the methods mentioned in other posts but this didn't work and the expiration was not extended - we are now here, with an invalid token and no further along.
It seems that the manual process of having to approve the OAuth request means that it is impossible to programatically get the feed of a public page.
Two years later, you can programmatically do this with a Facebook App (an example using PHP and Slim): https://developers.facebook.com/apps/
$base_api="https://graph.facebook.com/";
$client_id="XXXXXX";
$app_secret="XXXXXX";
//get a profile feed (can be from a page, user, event, group)
$app->get('/feed/:profileid/since/:start_date', function ($profile_id,$start_date) {
$start_time=date('m/d/Y h:i:s',$start_date);
$request = new FacebookRequest(
getSession(),
'GET',
'/'.$profile_id.'/feed?since='.$start_time
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
//do something with $graphObject
});
function getSession(){
$session = new FacebookSession(getAccessToken());
return $session;
}
function getAccessToken(){
global $base_api, $client_id, $app_secret;
$url=$base_api."oauth/access_token?client_id=".$client_id."&client_secret=".$app_secret."&grant_type=client_credentials";
$str = file_get_contents($url);
$token = str_replace ( "access_token=" , "" , $str );
return $token;
}
I have some success with reading in the direct feed without tokens etc.
(using magpie, simplepie or querypath or similar).
http://www.facebook.com/feeds/page.php?format=rss20&id=........
http://www.facebook.com/feeds/page.php?format=atom10&id=........
found on: http://ahrengot.com/tutorials/facebook-rss-feed/
Facebook has changed how to retrieve a public Facebook page's feed since the other answers were posted.
Check out my answer/question. It's not PHP, but it provides the URLs and process you need.

Categories