The sample of FQL query in FB is incorrect. Someone has a correct sample? - sql

The sample posted in the documentation, at:
http://developers.facebook.com/docs/reference/fql/
is incorrect and does not work. (php)
$fql_query_url = 'https://graph.facebook.com/'
. '/fql?q=SELECT+uid2+FROM+friend+WHERE+uid1=me()'
. '&' . $access_token;
$fql_query_result = file_get_contents($fql_query_url);
=> there are two / : ...facebook.com//fql...
=> the word "&access_token" is missing.
However, even issuing the correct url, the function does not seem to return anything...
Here is the code I have been using:
(function is passed $id, like 12345678)
$Fb = new Facebook(array('appId'=>FB_API_ID,'secret'=>FB_API_SECRET));
$access_token = $Fb->getAccessToken();
$fql_query_url = "https://graph.facebook.com/fql?q=SELECT+uid2+FROM+friend+WHERE+uid1=".$id."&access_token=" . $access_token;
$resp = file_get_contents($fql_query_url);
$var = json_decode($resp, true);
$txt .= "<br /><b>FQL QUERY:</b><br />" . display_tree($var);
Someone made it???

This query seems to work for me when I run it in the browser. Are you sure you have a valid access token?
Can you try it from the Graph API Explorer? Here's the link.

Related

Simple Yahoo Weather Api Not Working

I was using a simple code which includes a yahoo api code to get just the weather from my city and put in on my web page, however, i just read that yahoo public api is no longer working and i dont know how can a i get this code to work, i have a yahoo account, i created an api and i dont know how to proceed since here. If somebody can help me this is the code:
<?php
/*Clima*/
if(isset($_POST['zipcode']) && is_numeric($_POST['zipcode'])){
$zipcode = $_POST['zipcode'];
}else{
$zipcode = 'ARMA0056';
}
$result = file_get_contents('http://weather.yahooapis.com/forecastrss?p=' . $zipcode . '&u=c');
$xml = simplexml_load_string($result);
//echo htmlspecialchars($result, ENT_QUOTES, 'UTF-8');
$xml->registerXPathNamespace('yweather', 'http://xml.weather.yahoo.com/ns/rss/1.0');
$location = $xml->channel->xpath('yweather:location');
if(!empty($location)){
foreach($xml->channel->item as $item){
$current = $item->xpath('yweather:condition');
$forecast = $item->xpath('yweather:forecast');
$current = $current[0];
$clima = <<<END
<span>{$current['temp']}°C</span>
END;
}
}else{
$clima = '<h1>No results found, please try a different zip code.</h1>';
}
/*Clima*/
?>
just replace http://weather.yahooapis.com with http://xml.weather.yahoo.com. credits to https://forum.rainmeter.net/viewtopic.php?f=13&t=23010
xml.weather.yahoo.com was the solution, but the URL does not seem to be working anymore. Im now using yahoos query to get the XML i.e."https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%3D2489314"
This seems to be the same XML with the exception of "results" added to the tree.
Yahoo recently updated the way they handle requests. It used to be just over any connection, but now to make it more secure and easier to handle, they recently opted into sending all requests over OAuth1. Use the sample code they provide on their page and get the information from the request over JSON.
See https://developer.yahoo.com/weather/ for more information.
YAHOO changed some rules about api;
I made following class working for me... hope works for you;
$fcast=$phpObj->query->results->channel->item->forecast; change this line for other items...
<?php
date_default_timezone_set('CET');
class weatherfc{
public $result;
function weather($city){
$BASE_URL = "http://query.yahooapis.com/v1/public/yql";
$yql_query = 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="'.$city.'") and u="c"';
$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);
//var_dump($phpObj);
$weatherd='<div> Weather In '.$city.'<br>';
$fcast=$phpObj->query->results->channel->item->forecast;
foreach($fcast as $witem){
$fdate=DateTime::createFromFormat('j M Y', $witem->date);
$weatherd.= '<div class="days">';
$weatherd.= '<div class="item"><div>'.$fdate->format('d.m').' '.$witem->day.'</div><div class="image" style="width:90px !important; height:65px !important;"><img src="http://us.i1.yimg.com/us.yimg.com/i/us/nws/weather/gr/'.$witem->code.'d.png" width=90></div></div>';
$weatherd.= '<div><span>'.$witem->high.'°C</span>';
$weatherd.= '<span>'.$witem->low.'°C</span></div></div>';
};
$this->result=$weatherd;
}
}
$h= new weatherfc;
$h->weather("Antalya,Turkey");
echo $h->result;
?>
<style>
.days{
width:90px;
font-size:12px;
float:left;
font-family:Arial, Helvetica, sans-serif;
border:#999 1px dotted;
}
</style>

How to query REST API

I am using this code below to deal with the REST API query for Adobe Analytics. I always get the message "something went wrong" which means that the first IF is not active.
include_once('/path/SimpleRestClient.php');
$username = 'XXXXX';
$secret = 'XXXXX';
$nonce = md5(uniqid(php_uname('n'), true));
$nonce_ts = date('c');
$digest = base64_encode(sha1($nonce.$nonce_ts.$secret));
$server = "https://api.omniture.com";
$path = "/admin/1.4/rest/";
$rc=new SimpleRestClient();
$rc->setOption(CURLOPT_HTTPHEADER, array("X-WSSE: UsernameToken Username=\"$username\", PasswordDigest=\"$digest\", Nonce=\"$nonce\", Created=\"$nonce_ts\""));
$query="?method=Company.GetTokenUsage";
$rc->getWebRequest($server.$path.$query);
if ($rc->getStatusCode()==200)
{
$response=$rc->getWebResponse();
var_dump($response);
}
else
{
echo "something went wrong\n";
var_dump($rc->getInfo());
}
The $rc->getStatusCode(); does not exit. I get '404' when I use this line :
print_r ($rc->getStatusCode());
After googling, I found https://marketing.adobe.com/developer/blog/how-to-start-with-the-omniture-rest-api-in-php. It uses API version of 1.3 instead of 1.4. By updating the
$path = "/admin/1.4/rest/";
to
$path = "/admin/1.3/rest/";
I was able to stop getting 404 errors in the browser.

Youtube Next Previous Pagination with Json

I am getting nextPageToken from json result but still didn't work. Not no where problem exist, can anyone plz look into this and rectify and help me in this issue.
`
$jsonURL = file_get_contents("https://www.googleapis.com/youtube/v3/search?order=date&part=snippet&contentDetail&channelId= {$channelID}&type=video&maxResults=2&key={myAPiKey}");
$result = json_decode($jsonURL, true);
foreach ($result['items'] as $searchResult) {
$nPt = $result['nextPageToken'];
$Tmburl = $searchResult['snippet']['thumbnails']['high']['url'];
$views = $searchResult['statistics']['viewCount'];
$date = $searchResult['snippet']['publishedAt'];
echo '<h3>'.$searchResult['snippet']['title'].'</h3>';
echo '<img src="'.$Tmburl.'"/>';
echo '<p>'.$searchResult['snippet']['description'].'</p>';
}
// Pagination
echo '<h1>next</h1>';
`
The Next - Previous Pagination not working. Even i m getting nextPageToken number but link not functional.
I got, Just send pageToken value in Json URL, and pagination work.

Youtube API: losing data via curl in PHP?

I'm sure that this is likely a simple solution, but I can't see my error. I'm making an API call to youtube to get some basic information on a youtube video using the video's ID; specifically what I want is the (1) title, (2) description, (3) tags, and (4) thumbnail.
When I load an API url via my web browser, I see all the data. I don't want to paste the entire response in this question, but paste the following url in your browser and you'll see what I see: http://gdata.youtube.com/feeds/api/videos/_83A00a5mG4
If you look closely you'll see media:thumbnail, media:keywords, content, etc. Everything I want is there. Now the troubles...
When I load this same url through the following functions (which I copied from the Vimeo api...), the thumbnail and keywords simply aren't there.
function curl_get($url) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
$return = curl_exec($curl);
curl_close($curl);
return $return;
}
// youtube_get_ID is defined elsewhere...
$request_url = "http://gdata.youtube.com/feeds/api/videos/" . youtube_get_ID($url);
$video_data = simplexml_load_string(curl_get($request_url));
These functions do give me a response with some data, but the keywords and thumbnail are missing. Could anyone please tell me why my thumbnail and keywords are missing? Thank you for any help!
Here's the link for documentation on this.
Here's a function I wrote:
function get_youtube_videos($max_number, $user_name) {
$xml = simplexml_load_file('http://gdata.youtube.com/feeds/api/users/' . $user_name . '/uploads?max-results=' . $max_number);
$server_time = $xml->updated;
$return = array();
foreach ($xml->entry as $video) {
$vid = array();
$vid['id'] = substr($video->id,42);
$vid['title'] = $video->title;
$vid['date'] = $video->published;
//$vid['desc'] = $video->content;
// get nodes in media: namespace for media information
$media = $video->children('http://search.yahoo.com/mrss/');
// get the video length
$yt = $media->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->duration->attributes();
$vid['length'] = $attrs['seconds'];
// get video thumbnail
$attrs = $media->group->thumbnail[0]->attributes();
$vid['thumb'] = $attrs['url'];
// get <yt:stats> node for viewer statistics
$yt = $video->children('http://gdata.youtube.com/schemas/2007');
$attrs = $yt->statistics->attributes();
$vid['views'] = $attrs['viewCount'];
array_push($return, $vid);
}
return $return;
}
And here's the implementation:
$max_videos = 9;
$videos = get_youtube_videos($max_videos, 'thelonelyisland');
foreach($videos as $video) {
echo $video['title'] . '<br/>';
echo $video['id'] . '<br/>';
echo $video['date'] . '<br/>';
echo $video['views'] . '<br/>';
echo $video['thumb'] . '<br/>';
echo $video['length'] . '<br/>';
echo '<hr/>';
}

Help creating selective IF statement

I have this code that sends a text message to your mobile phone...
$text = fopen("../data/textmembers/registry.txt","r") or die("couldent open file");
while (!feof($text)) {
$name = fgets($text);
$number = fgets($text);
$carrier = fgets($text);
$date = fgets($text);
$line = fgets($text);
$content = $_POST['message'];
$message .= $content;
$message .= "\n";
$number = trim($number);
mail($number . "#vtext.com", "SGA Event Alert", $message, "SGA");
Header("Location: mailconf.php");
everything works fine.. Here is my question, if you look at where I have "#vtext.com"
as you may or may not know, each carrier has its own extension, verizon is #vtext.com, at&t is #txt.att.net. I need to take the feed from "$carrier" decide what carrier it is, and then assign the extension to it...
I thought an ifelse would work, but I am not good with if statements...
the user's choices are
Verizon = 1234567890#vtext.com
AT&T = 1234567890#txt.att.net
T-mobile = #tmomail.net
Nextel = #messaging.nextel.com
thanks guys!!
$carriers = array(
"verizon" => "vtext.com",
"at&t" => "txt.att.net",
"t-mobile" => "tmomail.net",
"nextel" => "messaging.nextel.com"
);
Then, you get that value by looking up the key:
print $carriers[strtolower($carrier)];
If $carrier is "Nextel," "messaging.nextel.com" will be returned.
Probably better than using an if statement would be using a switch statement.
Have a look at the section of the PHP manual that deals with the switch statement.