Google contacts api parsing xml and get contact title - php

I'm using oauth 2.0 and I trying to use contacts google api.
$url = 'https://www.google.com/m8/feeds/contacts/default/full?v=2.0&max-results='.$max_results.'&oauth_token='.$accesstoken;
Result of this I have there: $xmlresponse result is fine and good (it means that not have issues)
$xml = new SimpleXMLElement($xmlresponse);
$xml->registerXPathNamespace('atom', 'http://schemas.google.com/g/2005#kind');
$result = $xml->xpath('//atom:title');
var_dump($xml);
var_dump($result);
foreach ($result as $title) {
echo $title->attributes()->address . "<br>";
}
I want to get title contact (in var_dump($xml) it is visible as 'title') but $result is empty
Question:
1) How to get title contact from this xml response ?

Related

Grab/Fetch Facebook comments through query.using Graph API

So I was trying to fetch facebook comments then put it into my own website so then I could reply it through my website. After doing some research, I found it Graph API could be the solution to my problem. Below is the code
<?php
$group_id ="14********_1**********99";
$access_token="accesstoken";
$url = "https://graph.facebook.com/v2.11/" . $group_id .
"/comments?
fields=message,from{name,id}&access_token=".$access_token;
$json= file_get_contents($url);
$data = json_decode($json);
foreach ($data->comments->data as $key) {
if(isset($key->message))
{
echo $key->message;
echo "<br>";
}
}
?>
How do I fetch comments from Facebook through the URL above? Sorry I'm still new to programming.

yahoo import contacts through yql giving error

I am trying to import yahoo contacts with help of YQL but stuck with a problem.
I am using approach on this link https://developer.yahoo.com/yql/guide/yql-code-examples.html#yql_php
But I got this error:
{"error":{"lang":"en-US","description":"Authentication Error. The table social.contacts requires a higher security level than is provided, you provided ANY but at least USER is expected"}}
Do I am missing something
I have run this query on yql console its showing result but nt getting results directly hitting url or with curl.
My code is :
$BASE_URL = "https://query.yahooapis.com/v1/public/yql";
// Form YQL query and build URI to YQL Web service
$yql_query = "select * from social.contacts(0, 500) where guid=me";
$yql_query_url = $BASE_URL . "?q=" . urlencode($yql_query) . "&format=json";
// Make call with cURL
$session = curl_init($yql_query_url);
curl_setopt($session, CURLOPT_RETURNTRANSFER,true);
$json = curl_exec($session);
// Convert JSON to PHP object
$phpObj = json_decode($json);
// Confirm that results were returned before parsing
if(!is_null($phpObj->query->results)){
// Parse results and extract data to display
foreach($phpObj->query->results->event as $event){
$events .= "<div><h2>" . $event->name . "</h2><p>";
$events .= html_entity_decode(wordwrap($event->description, 80, "<br/>"));
$events .="</p><br/>$event->venue_name<br/>$event->venue_address<br/>";
$events .="$event->venue_city, $event->venue_state_name";
$events .="<p><a href=$event->ticket_url>Buy Tickets</a></p></div>";
}
}
// No results were returned
if(empty($events)){
$events = "Sorry, no events matching $query in $location";
}
// Display results and unset the global array $_GET
echo $events;
unset($_GET);

How extract information from a json retrieved from an API?

I'm trying to get somes informations from an API but I always failed.
The API code :
{"matches":[{"matchId":2032325149,"region":"EUW","platformId":"EUW1","matchMode":"CLASSIC","matchType":"MATCHED_GAME","matchCreation":1427400448291,"matchDuration":2225,"queueType":"RANKED_SOLO_5x5","mapId":11,"season":"SEASON2015","matchVersion":"5.6.0.190","participants":[{"teamId":100,"spell1Id":3,"spell2Id":4,"championId":53,"highestAchievedSeasonTier":"UNRANKED","timeline":{"creepsPerMinDeltas":{"zeroToTen":0.9,"tenToTwenty":0.9,"twentyToThirty":0.6,"thirtyToEnd":1.2},"xpPerMinDeltas":{"zeroToTen":253.60000000000002,"tenToTwenty":237.8,"twentyToThirty":477.29999999999995,"thirtyToEnd":448.4},"goldPerMinDeltas":{"zeroToTen":128.2,"tenToTwenty":169.6,"twentyToThirty":310.9,"thirtyToEnd":211.2},"csDiffPerMinDeltas":{"zeroToTen":-0.8,"tenToTwenty":-0.5499999999999998,"twentyToThirty":-1.2499999999999998,"thirtyToEnd":-0.30000000000000027},"xpDiffPerMinDeltas":{"zeroToTen":-12.299999999999983,"tenToTwenty":-127.04999999999998,"twentyToThirty":120.09999999999997,"thirtyToEnd":-491.9},"damageTakenPerMinDeltas":{"zeroToTen":187.2,"tenToTwenty":644.0999999999999,"twentyToThirty":1015.2,"thirtyToEnd":2076.2},"damageTakenDiffPerMinDeltas":{"zeroToTen":9.149999999999963,"tenToTwenty":32.49999999999997,"twentyToThirty":126.24999999999991,"thirtyToEnd":762.9000000000001},"role":"DUO_SUPPORT","lane":"BOTTOM"},"masteries":[{"masteryId":4211,"rank":2},{"masteryId":4213,"rank":2},{"masteryId":4221,"rank":1},{"masteryId":4222,"rank":3},{"masteryId":4232,"rank":1},{"masteryId":4233,"rank":3},{"masteryId":4234,"rank":3},{"masteryId":4244,"rank":1},{"masteryId":4312,"rank":3},{"masteryId":4313,"rank":3},{"masteryId":4322,"rank":1},{"masteryId":4324,"rank":1},{"masteryId":4331,"rank":3},{"masteryId":4334,"rank":1},{"masteryId":4341,"rank":1},{"masteryId":4342,"rank":1}],"stats":{"winner":false,"champLevel":15,"item0":2049,"item1":3401,"item2":3270,"item3":2010,"item4":3110,"item5":3082,"item6":3340,"kills":1,"doubleKills":0,"tripleKills":0,"quadraKills":0,"pentaKills":0,"unrealKills":0,"largestKillingSpree":0,"deaths":11,"assists":10,"totalDamageDealt":31311,"totalDamageDealtToChampions":9198,"totalDamageTaken":31747,"largestCriticalStrike":0,"totalHeal":3600,"minionsKilled":36,"neutralMinionsKilled":0,"neutralMinionsKilledTeamJungle":0,"neutralMinionsKilledEnemyJungle":0,"goldEarned":8264,"goldSpent":8055,"combatPlayerScore":0,"objectivePlayerScore":0,"totalPlayerScore":0,"totalScoreRank":0,"magicDamageDealtToChampions":7159,"physicalDamageDealtToChampions":2038,"trueDamageDealtToChampions":0,"visionWardsBoughtInGame":0,"sightWardsBoughtInGame":0,"magicDamageDealt":22000,"physicalDamageDealt":5572,"trueDamageDealt":3737,"magicDamageTaken":15037,"physicalDamageTaken":16608,"trueDamageTaken":102,"firstBloodKill":false,"firstBloodAssist":false,"firstTowerKill":false,"firstTowerAssist":false,"firstInhibitorKill":false,"firstInhibitorAssist":false,"inhibitorKills":0,"towerKills":0,"wardsPlaced":28,"wardsKilled":1,"largestMultiKill":1,"killingSprees":0,"totalUnitsHealed":4,"totalTimeCrowdControlDealt":445},"participantId":0,"runes":[{"runeId":5273,"rank":9},{"runeId":5289,"rank":9},{"runeId":5317,"rank":9},{"runeId":5357,"rank":3}]}],"participantIdentities":[{"participantId":0,"player":{"summonerId":66366116,"summonerName":"name","matchHistoryUri":"/v1/stats/player_history/EUW1/217404427","profileIcon":690}}]}]}
I'm trying to get "Kills" value and this is my php code :
<?php
$result = file_get_contents('API URL LINK HERE);
$key = json_decode($result);
print '<p><b>' . $key->matches->participants->stats->Kills . '</b></p>';
?>
Please can someone correct my code ?
Thanks a lot.
<?php
$json = '{"matches":[{"matchId":2032325149,"region":"EUW","platformId":"EUW1","matchMode":"CLASSIC","matchType":"MATCHED_GAME","matchCreation":1427400448291,"matchDuration":2225,"queueType":"RANKED_SOLO_5x5","mapId":11,"season":"SEASON2015","matchVersion":"5.6.0.190","participants":[{"teamId":100,"spell1Id":3,"spell2Id":4,"championId":53,"highestAchievedSeasonTier":"UNRANKED","timeline":{"creepsPerMinDeltas":{"zeroToTen":0.9,"tenToTwenty":0.9,"twentyToThirty":0.6,"thirtyToEnd":1.2},"xpPerMinDeltas":{"zeroToTen":253.60000000000002,"tenToTwenty":237.8,"twentyToThirty":477.29999999999995,"thirtyToEnd":448.4},"goldPerMinDeltas":{"zeroToTen":128.2,"tenToTwenty":169.6,"twentyToThirty":310.9,"thirtyToEnd":211.2},"csDiffPerMinDeltas":{"zeroToTen":-0.8,"tenToTwenty":-0.5499999999999998,"twentyToThirty":-1.2499999999999998,"thirtyToEnd":-0.30000000000000027},"xpDiffPerMinDeltas":{"zeroToTen":-12.299999999999983,"tenToTwenty":-127.04999999999998,"twentyToThirty":120.09999999999997,"thirtyToEnd":-491.9},"damageTakenPerMinDeltas":{"zeroToTen":187.2,"tenToTwenty":644.0999999999999,"twentyToThirty":1015.2,"thirtyToEnd":2076.2},"damageTakenDiffPerMinDeltas":{"zeroToTen":9.149999999999963,"tenToTwenty":32.49999999999997,"twentyToThirty":126.24999999999991,"thirtyToEnd":762.9000000000001},"role":"DUO_SUPPORT","lane":"BOTTOM"},"masteries":[{"masteryId":4211,"rank":2},{"masteryId":4213,"rank":2},{"masteryId":4221,"rank":1},{"masteryId":4222,"rank":3},{"masteryId":4232,"rank":1},{"masteryId":4233,"rank":3},{"masteryId":4234,"rank":3},{"masteryId":4244,"rank":1},{"masteryId":4312,"rank":3},{"masteryId":4313,"rank":3},{"masteryId":4322,"rank":1},{"masteryId":4324,"rank":1},{"masteryId":4331,"rank":3},{"masteryId":4334,"rank":1},{"masteryId":4341,"rank":1},{"masteryId":4342,"rank":1}],"stats":{"winner":false,"champLevel":15,"item0":2049,"item1":3401,"item2":3270,"item3":2010,"item4":3110,"item5":3082,"item6":3340,"kills":1,"doubleKills":0,"tripleKills":0,"quadraKills":0,"pentaKills":0,"unrealKills":0,"largestKillingSpree":0,"deaths":11,"assists":10,"totalDamageDealt":31311,"totalDamageDealtToChampions":9198,"totalDamageTaken":31747,"largestCriticalStrike":0,"totalHeal":3600,"minionsKilled":36,"neutralMinionsKilled":0,"neutralMinionsKilledTeamJungle":0,"neutralMinionsKilledEnemyJungle":0,"goldEarned":8264,"goldSpent":8055,"combatPlayerScore":0,"objectivePlayerScore":0,"totalPlayerScore":0,"totalScoreRank":0,"magicDamageDealtToChampions":7159,"physicalDamageDealtToChampions":2038,"trueDamageDealtToChampions":0,"visionWardsBoughtInGame":0,"sightWardsBoughtInGame":0,"magicDamageDealt":22000,"physicalDamageDealt":5572,"trueDamageDealt":3737,"magicDamageTaken":15037,"physicalDamageTaken":16608,"trueDamageTaken":102,"firstBloodKill":false,"firstBloodAssist":false,"firstTowerKill":false,"firstTowerAssist":false,"firstInhibitorKill":false,"firstInhibitorAssist":false,"inhibitorKills":0,"towerKills":0,"wardsPlaced":28,"wardsKilled":1,"largestMultiKill":1,"killingSprees":0,"totalUnitsHealed":4,"totalTimeCrowdControlDealt":445},"participantId":0,"runes":[{"runeId":5273,"rank":9},{"runeId":5289,"rank":9},{"runeId":5317,"rank":9},{"runeId":5357,"rank":3}]}],"participantIdentities":[{"participantId":0,"player":{"summonerId":66366116,"summonerName":"name","matchHistoryUri":"/v1/stats/player_history/EUW1/217404427","profileIcon":690}}]}]}';
$data = json_decode($json, true);
echo $data['matches'][0]['participants'][0]['stats']['kills'];
?>

Twitter API v 1.1 code in PHP

I am using twitter API v1.1 to get tweets in my web application the code for getting tweets is as
$name = 'zkalvi';
$url = "https://api.twitter.com/1.1/search/tweets.json/".$name;
$tweets = json_decode(file_get_contents($url));
echo '<ul>';
foreach($tweets as $tweet) {
echo '<li>'.$tweet->text.'</li>';
}
echo '</ul>';
and $name = 'zkalvi';
$url = "https://api.twitter.com/1.1/search/tweets.json/".$name;
$tweets = simplexml_load_file($url);
echo '<ul>';
foreach($tweets as $tweet) {
echo '<li>'.$tweet->text.'</li>';
}
echo '</ul>';
both of these codes are not showing the tweets.
Please help me why the tweets are not showing and how could I show the tweets?
Thanks in advance.
first of all, the way you are calling is wrong, your url should be like this
https://api.twitter.com/1.1/search/tweets.json?q=zkalvi.
By this url you will get following output
{"errors":[{"message":"Bad Authentication data","code":215}]}
This is because , in twitter 1.1 version, most of thing needs authentication. So better you use twitter server side library for getting results.
Here is link for twitteroauth library for php
twitteroauth

RESTFUL web service response parsing issue

I am getting the restful web service response as well. But I am not able to parse it properly
my code looks like this
include 'RestClient.class.php';
error_reporting(E_ALL);
// Client Profile
$url = "http://localhost/lgen/index.php/api/client";
$ex = RestClient::get($url,array('requestType' =>'viewClientProfile',
'username' => 'uname',
'pass' =>'pass'));
echo $response = $ex->getResponse();
$xml = simplexml_load_string($response);
when print $response I am getting data on browser but while trying to parse it am not getting any kind of data
echo $response = $ex->getResponse();
You are creating and echoing a variable at the same time.
Try this:
$xml = simplexml_load_string($ex->getResponse());
var_dump($xml);

Categories