How to retrieve expanded_url entity form twitter json feed - php

need to get the expanded url from a tweet. Heres my incorrect code:
$twitter_data = json_decode($rss,true);
for($i=0;$i<100;$i++){
$iurlx = $twitter_data['results'][$i]['entities']['urls']['expanded_url'];
How to fix this as simply as possible?

Related

Facebook Graph API- Page post fetch in website

I used following code to access facebook page posts.
$accessToken = 'EAAlGssgdgQIBAHuD9ZBZB6RWZClM3bmm8Vjv2nZBNmotTTnubgzdK4aiHbqJwhRlELjAurPEHKSqxJS7c0Pyd5ZBuqZAo2keabbkubx0AZCl3m6brDGlkXNgMq9dtNUZAx4P6QwdsXwNvJaEi2j3YDsHpZABiRxRK6qMAmZAyynLvJNCJ41ZBn9se28QUsDHG72mhZCzHFLpLQUxZCAZDZD';
$id = '109395947376896';
$url = "https://graph.facebook.com/$id/posts?access_token=$accessToken";
$result = file_get_contents($url);
$decoded = json_decode($result, true);
var_dump($decoded);
and get the following result. screenshot is attached
how do I get images of posts??
Without specifying the fields, you will only get default ones. This is how you can get fields (checkout the API docs for Posts about available ones):
$url = "https://graph.facebook.com/$id/posts?access_token=$accessToken&fields=full_picture,message,...";
Source: https://developers.facebook.com/docs/graph-api/reference/post/#fields
You can get them in field parameters
picture
full_picture
child_attachments
Also refer https://developers.facebook.com/docs/graph-api/reference/post/

how to collect data to array from json apicall response (execute('GET', $url)

I got this API sample code from my webshop provider. It's use to get data from my webshop database directly:
require_once dirname(__FILE__) . '/classes/apicall.php';
$username = 'extreme';
$apiKey = 'xxxx';
$apiCall = new ApiCall($username, $apiKey);
$apiCall->setFormat('json');
$url = 'extreme.api.shoprenter.hu/products/cHJvZHVjdC1wcm9kdWN0X2lkPTQ0NDE=';
$response = $apiCall->execute('GET', $url);
echo '<pre>';
print_r($response->getParsedResponseBody());
The output looks like this:
http://data.extremeaudio.hu/api/product.php
My task is to gather data from this output into an array or something, so i can use it to refresh my product prices dinamically in a html based javascript banner page here:
http://data.extremeaudio.hu/tv/
So please guide me, how can I collect this part:
[price] => 23621.2600
to display the actual price inside the banners.
I'm absolutely NOT a php expert - as you see - so please if you help, use examples or detailed comments.
Thanks a lot!
With $response->getParsedResponseBody() you have an array.
Save this array to an var $var = $response->getParsedResponseBody();.
Then you can access price via $var['price'];;

Requesting User Info with Foursquare API

I am using the Foursquare API to request information for my users.
It says to make a request to get user info like this,
https://api.foursquare.com/v2/users/self?oauth_token=TOKENHERE
So I am doing it like this,
$fsUser = file_get_contents("https://api.foursquare.com/v2/users/self?oauth_token=".$access_token);
When I var_dump I get null from the value I am saving it in, Here is what my full code looks like,
<?php
$client_id = "iwdhwouchweohcuwoehcowehcu";
$secret = "ojdwojwjwrhvo";
$redirect = "http://www.example.com";
if($_GET['code']){
//We need to hit up the authkey URL and get the key in JSON format
$authkey = file_get_contents("https://foursquare.com/oauth2/access_token?client_id=".$client_id."&client_secret=".$secret."&grant_type=authorization_code&redirect_uri=".$redirect."&code=".$_GET['code']);
//We then need to decode it and store that key in a variable
$auth = json_decode($authkey,true);
$access_token = $auth['access_token'];
//we then look up whatever endpoint of the api we want
$fsUser = file_get_contents("https://api.foursquare.com/v2/users/self?oauth_token=".$access_token);
$user = json_decode($fsUser, true);
// $name = $decoded_userinfo['response']['user']['firstName'];
}
?>
When I var_dump $fsUser I get bool(false)
I have var_dump every variable with no issues till I get to $fsUser I can not get past this part...
You also need to use the version number (v) with your request.
Like this
https://api.foursquare.com/v2/venues/search?client_id=CLIENT_ID&v=20140806&m=foursquare
See documentation here.
https://developer.foursquare.com/overview/versioning

How find Distance between two addresses through php

i am looking for some help to find the distance between two address through php
as i can not use the google maps api. so get a way from this post
Distance between two addresses
but i need to know how can send the request using URL pattern
and grab the repose to save them in database.
http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New+York,+NY,+United+States&sensor=false
thanks for any suggestion.
///////////////
After these answers i am there
$customer_address_url = urlencode($customer_address);
$merchant_address_url = urlencode($merchant_address);
$map_url = "http://maps.google.com/maps/api/directions/xml?origin=".$merchant_address_url."&destination=".$customer_address_url."&sensor=false";
$response_xml_data = file_get_contents($map_url);
$data = simplexml_load_string($response_xml_data);
XML response is visible when i put this url : http://maps.google.com/maps/api/directions/xml?origin=Quentin+Road+Brooklyn%2C+New+York%2C+11234+United+States&destination=550+Madison+Avenue+New+York%2C+New+York%2C+10001+United+States&sensor=false
but can not printing through
echo "<pre>"; print_r($data); exit;
You can try this..
$url = "http://maps.google.com/maps/api/directions/xml?origin=550+Madison+Avenue,+New+York,+NY,+United+States&destination=881+7th+Avenue,+New+York,+NY,+United+States&sensor=false";
$data = file_get_contents($url);
Now $data contains resulting xml data. You can parse this xml data using..
http://php.net/manual/simplexml.examples.php
use the haversine formula
Also check https://developers.google.com/maps/documentation/distancematrix/

Google social Graph response decode

I would like make a script that automatically insert in a Array the Google+ ID's fetched from
the SocialGraphs Api but i can't understand the type of this result,here's the example of the result: http://pastebin.com/wfBAtjH7
If can be help,i've seen the method for isolate the ID's done in Javascript:
var oids = [];
var reobg = new RegExp("\\d{21}","g"); // only interested in user ID so prepare regexp
oids = resp.match(reobg); // get an array of ids
if (!oids == null){ // if something stringify it
oids = oids.join(",");
}
For get in a variable all the text,i've used this code:
$gplus = file_get_contents('https://plus.google.com/u/0/_/socialgraph/lookup/visible/?o=[null,null,"103227580967788703328"]&rt=j');
Where 103227580967788703328 is an example Google Plus ID.
Thanks in advance.
Kind Regards.
Luca.
Try and cycle through the input with this regex:
\[\[,,"(\d+)"\]
and grab the first group each time.
Try this \[(.*),(.*),"(.*)"\] this is may help U.

Categories