Using API to get Covers - URL Error - php

I need some album covers for my PHP website but something is not working anymore.
I was using a JSON to get Album ID and then i was using this id to get the album cover.
My problem is that i try to decode a json from website but i don't get any result anymore (it was working before ...).
Here is the code (getting JSON and decoding it) :
$req="http://api-v3.deezer.com/1.0/search/track/?q=".$deezer."&index=0&nb_items=8&output=json";
$result = file_get_contents($req);
$testjson=json_decode($result,true);

I think you are using an old code of Deezer api (1.0 and I don't get any JSON from your url).
Try to change $req by :
$req="http://api.deezer.com/2.0/search/album/?q".$deezer."&index=0&nb_items=8&output=json";
Then, some code are missing and are important to change too.
When you try to get your image, don't forget to change the url too with that version (2.0).
You can find more information on Deezer Api : here.

Related

Spotify PHP Api - {"error":"unsupported_grant_type","error_description":"grant_type parameter is missing"}. Tried everything

EDIT
I found that if I edit the code to not use http_build_query($parameters);
to convert array of parameters into the url-string, but pass the strings directly to the url it works. So how is http_build_query destroying the grant_type= authorization_code?
ORIGINAL:
I'm using the php sdk api https://github.com/jwilsson/spotify-web-api-php
and trying to connect the user. I log in using the link
https://accounts.spotify.com/authorize?
client_id=--id--
&redirect_uri=https%3A%2F%2Fwww.testsite.com%2Fspotify_connect%2F
&response_type=code
&scope=user-read-email
and get a code in return and I've traced the code towards the curl in Request->send()
the full link is
https://accounts.spotify.com/api/token?
client_id=--client--&
code=--returned_code--
&grant_type=authorization_code
&redirect_uri=https%3A%2F%2Fwww.testsite.com%2Fspotify_connect%2F
&client_secret=--secret--
I get this in return:
{"error":"unsupported_grant_type","error_description":"grant_type parameter is missing"}
I've tried sending the authorization in the header as well. Same result
Authorization: Basic base64_encode(--clientid--:--clientsecret--);
What am I doing wrong?
Using the
https://accounts.spotify.com/api/token?grant_type=client_credentials
is working like a charm, but using the code I get in return does not work.
Thanks for help :)

How to get video from Instagram public access API?

I know that this api is working to get images but how about videos?
https://www.instagram.com/username/?__a=1
I was able to get the thumbnail of the video but not the source or the url itself.
When you make above API call it would return code in it. looks something like this: BWhyIhRDBCw
Whenever your media nodes has "is_video": true you can make following call:
https://www.instagram.com/p/{code}/?__a=1
for e.g.,
https://www.instagram.com/p/BWhyIhRDBCw/?__a=1
This would return another json. which will have video_url you are looking for.
sample:
"video_url": "https://scontent-bom1-1.cdninstagram.com/vp/437699b67172f450331fa732f0777b18/5A7FE0A0/t50.2886-16/20138822_486349355081174_1539674401849475072_n.mp4",
This url working in local machine but not on my remote server.
When i try to hit from remote server its returning html content.
To hit this api simply use volly library it will return json then u can parse json as per your need.

Assigning JSON Value to PHP Array from Google Maps API Query

I am trying to find a way to assign the JSON value Google Map's API Returns when passed an address. I would search Google, but I am only a few month deep into PHP and really don't know what keywords to use. I really don't even know what a JSON is?
Anyway, I found this article that explains how to query Google Maps with an address and have it return a GPS Location. When I tested it in my browser, the text appears. I just don't know what to use to take what the browser is displaying and assign in to an Object in a PHP page.
This is the Google Maps Query:
http://maps.google.com/maps/geo?q="ADDRESS"&output=csv&oe=utf8
This my function where I want to use this:
//Queries Google Map's API with an address and assigns the returned GPS Location
//to this Object
public function build_me($this_address)
{
//Builds the query from the address array to send to the Goole Maps API
$query = $this_address["Line1"].",".$this_address["Line2"].",".
$this_address["City"].",".$this_address["State"].",".$this_address["Zip"];
//Location_Array = http://maps.google.com/maps/geo?q=$query&output=csv&oe=utf8
$this->latitude = //Location_Array['Something'];
$this->longitude = //Location_Array['Something'];
}
This is the article that I am referring to:
http://martinsikora.com/how-to-get-gps-coordinates-from-an-address
My question is, how would I go about doing this? Are there any good tutorials on this?
Thanks in advance for anyone pointing me in the right direction!
Actually the URL you are showing will produce a CSV output (that is why it has the output=csv parameter). You can see it if you simply insert it into your browser (Downing Street 10):
200,8,45.9797693,-66.5854067
Here are some useful resources to get the job done:
cURL to make the call to the Google API
cURL Tutorial
str_getcsv() to parse a CSV string into a PHP array
(json_decode() to translate JSON to PHP arrays/objects - just in case you're gonna need it later)

Getting a facebook name out of a fb id - file_get_contents() not working

Background:
I am making a facebook app where users post messages like in a forum. For that I save the users facebook id to then present their names. I know it is possible to show the name out of a facebook id by using the Graph API, but I can't make it work.
The code I use is the following:
//$fbId is the facebook id to find out the name for
$facebookUrl = "https://graph.facebook.com/".$fbId;
echo(file_get_contents($facebookUrl));
$str = file_get_contents($facebookUrl);
$result = json_decode($str);
echo($result);
return $result->name;
I researched and tested this for hours, but I feel like I'm getting nowhere. I got an idea of how it works from:
http://www.phpexpertsforum.com/how-to-get-the-facebook-name-with-user-id-using-php-code-t1852.html
Didn't work so I researched further from here:
Get user's name from Facebook Graph API
I dowloaded and currently use the Facebook php SDK, but I don't find the way to use it to get anyone's name other than the current user.
The problem here seems to be the file_get_contents() function that returns a false, meaning that it can't read the file.
I checked out the php documentation. Also, by using the php functions fopen() and file().
//echo(pathinfo($facebookUrl, PATHINFO_EXTENSION)); -> Doesn't give any response!
//echo(file_exists($facebookUrl)); -> No response!
//fopen() doesn't work
//file() doesn't work
//file_get_contents() doesn't work
//tried adding an access token to the $facebookUrl but it doesn't make any difference
Any idea of what could be wrong here? Little guidance would be very helpful. What am I doing wrong? What did I miss?
Seems that your allow_url_fopen directive is set to Off.
Look for it in your php.ini (or create a php file containing <?php phpinfo(); ?> and point to it in your browser) and check if is set to 'On'.

How to fetch youtube video data using php?

I need to get the XML data from youtube for a particular video(based on ID) and fetch the thumbnail url. I am using PHP.
The code is as follows:
<?php
//$xmlFilePath = 'http://localhost/testFile.xml'; //This works..
$xmlFilePath = 'https://gdata.youtube.com/feeds/api/videos/5P6UU6m3cqk?v=2';
$dataFromYoutube = file_get_contents($xmlFilePath);
print_r($dataFromYoutube);
?>
I dont get any data. The output is blank. If I load the url 'https://gdata.youtube.com/feeds/api/videos/5P6UU6m3cqk?v=2' in browser and copy the content to a file(http://localhost/testFile.xml), then the above code works.
I have tried fetching the youtube data using ajax and also simlexml_load_file function in php. But the result is blank/empty for Youtube url. However, I get the data for 'http://localhost/testFile.xml' in both cases.
How can I fetch youtube data using php?
Please help.
well, your code is correct and works fine too. It may be that your apache server is not configured for "https". So just check it once too.

Categories