I'm trying to get nearby venues. I found this url where i can just plug in lat and lon.
How do i use this URL? I tried getting the libraries from Foursquare API site, but can't get them to work.
I know i can json_decode the result on this page to get a php object, but how do i make a call and get the data to my webpage?
https://api.foursquare.com/v1/venues.json?geolat=40.562362&geolong=-111.938689&l=10
Thanks
$data = file_get_contents(http://MyURL/);
$results = json_decode($data, true); //true = making it into array, not object
Related
I use the Amazon product advertising API to retrieve product information on my websit in a JSON array.
When calling the API, an example result I am getting is the following, which is shown when using print_r($response).
{"ItemsResult":{"Items":[{"ASIN":"B010FTYIUS","DetailPageURL":"https://www.amazon.com/dp/B010FTYIUS?tag=hangarflights-20&linkCode=ogi&th=1&psc=1","Offers":{"Listings":[{"Id":"DAjnW3%2BLO70EsyLN%2FMQLwyvR8afWckVN8fvJ6mojtJQMdPh0yCEgxtv3gBjPMOwUQp8RvEP56ao%2FWFAtjhHkFRQRsYs27pFtiLuL9DiaqdIprrqGBw03IQ%3D%3D","Price":{"Amount":1095.95,"Currency":"USD","DisplayAmount":"$1,095.95"},"ViolatesMAP":false}]}}]}}
How can I get, for example, just the price amount (here 1095.95)? I have tried multiple things such as echo $response["ItemsResult"]["items"]["Offers"]["Listings"]["Price"]["Amount"] but without success.
$response = '{"ItemsResult":{"Items":[{"ASIN":"B010FTYIUS","DetailPageURL":"https://www.amazon.com/dp/B010FTYIUS?tag=hangarflights-20&linkCode=ogi&th=1&psc=1","Offers":{"Listings":[{"Id":"DAjnW3%2BLO70EsyLN%2FMQLwyvR8afWckVN8fvJ6mojtJQMdPh0yCEgxtv3gBjPMOwUQp8RvEP56ao%2FWFAtjhHkFRQRsYs27pFtiLuL9DiaqdIprrqGBw03IQ%3D%3D","Price":{"Amount":1095.95,"Currency":"USD","DisplayAmount":"$1,095.95"},"ViolatesMAP":false}]}}]}}';
$response = json_decode($response, true);
echo $response["ItemsResult"]["Items"][0]['Offers']["Listings"][0]["Price"]["Amount"]; //1095.95
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>.";
?>
I am trying to get and array of more then 900 ids in this way, but I get an error message.
$url = 'https://graph.facebook.com/?ids=' . implode(',', $array);
$result = file_get_contents($url);
I think because the list is too big I got this error - if I shorten the list facebook gets me the JSON.
Is there any suggestion to get it in another fashion? (maybe batch call, or something like curl? )
The only other way is to implement a batch call with smaller API calls.
https://developers.facebook.com/docs/graph-api/making-multiple-requests
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
I want to use Twitter Trends, but not limited to the last ten trends. However I do not understand the API.
My basic code is...
$woeid = 2459115;
$json = file_get_contents("https://api.twitter.com/1/trends/".$woeid.".json", true);
$decode = json_decode($json, false);
$data = $decode[0]->trends;
foreach ($data as $item) {
...
}
When i create an app with Twitter, I see...
Signature base string... Authorization header... cURL command...
with
Request type: GET Request URI: https://api.twitter.com/1/
But how to deal with this?
Thanks,
V.
No, the API itself returns only 10 trends. It doesn't require creating an app, or authentication to return more trends, the trends API is public.
https://dev.twitter.com/docs/api/1/get/trends/%3Awoeid
Returns the top 10 trending topics for a specific WOEID, if trending information is available for it.
Edit: Yeah your code is correct.