need help Displaying more than 1 response from FQL query is_app_user Or Similar solutions - facebook-fql

I am currently trying to get a list of friends who have added the same app via the FQL query.
I am actually doing this for a school project, and apparently, the server where this is going to be saved is not supported via PHP.That is why i am using the JavaScript SDK to code this.
This is actually the first time that I am doing a project in Facebook and everything is extremely new to me and having the graph api is not helping with me with any old documentations at all since many things have been changed and documentation is very scarce >.<.
Currently, I am having problems displaying multiple results (i am only able to do so if i hard code the response)
I've tried using a for loop to print the result but to no avail.
FB.api('/me', function(response) {
showLoader(false);
var query = FB.Data.query('SELECT uid, name, pic_square FROM user WHERE uid
IN (SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user');
query.wait(function(rows) {
for(var i = 0; i< rows.length;i++)
{
document.getElementById('debug').innerHTML =
''+ rows[i].name +"<br />" + "<img src=\""+ rows[i].pic_square +"\" /><br />";
}
});
});
am i doing this wrong in any way? >.<. Any help would be reallllly great!!
Thanks!

Maybe it is the fact that you are stepping over what you are placing in the debug div. Try
document.getElementById('debug').innerHTML +=
Also, you do not have to have a for loop. You can have facebook do it for you by using their forEach function.
To get multiple results returned, I do this:
var linkquery = FB.Data.query('select owner, owner_comment, url from link where owner={0}', response.id);
FB.Data.waitOn([linkquery], function() {
FB.Array.forEach(linkquery.value, function(row) {
document.getElementById('debug').innerHTML += 'FQL Information: '+ "<br />" +
'Your name: ' + row.owner + "<br />" +
'Your comment: ' + row.owner_comment + "<br />" +
'Your link: ' + "<a href='" + row.url + "'>" + row.url + "</a><br /><br />";
});
});
The FB.Array.forEach gets each row.owner and they are being added to the debug div -
document.getElementById('debug').innerHTML +=
with each row that is returned.
Hope that helps

Related

how to get azure devops api data usign javascript extract in table format

$(document).ready(function() {
$.ajax({
url: 'https://dev.azure.com/{org}/infosoftaz/_apis/wit/workitems/1?api-version=7.0',
type:"GET",
dataType: 'json',
headers: {
'Authorization': 'Basic' + btoa("" + ":" + '{PAT}')
},
}).done(function( results ) {
console.log( results );
result = JSON.stringify(results);
var div = "";
div += "<p>" + result + "</p>";
div += "<p class='description'>" + result + "</p>";
$('#data_fetch').html(div);
});
});
<div id="data_fetch"></div>
Column A
Column B
Cell 1
Cell 2
Cell 3
Cell 4
According to your description, you can refer to this answer and then extract the result in html table.
Use:
JSON.parse(results)
Please check if it meets your requirements.

Leaflet - UTFGrid - add popup

I know it's a beginner question and probably very easy but I can't get it to work. I have a map with 2 utfgrids which show an information about bicycle and hiking routes. It is based on this example:
http://bl.ocks.org/milkbread/6449317
It works fine but I would like to change it this way. When hoovering the existing infobox should show up but when clicking on the route the popup should show up in the place where I clicked (with the same information that shows up in the infobox).
I tried different ways to apply it but I always get an error. Here's a link to my working webiste and a part of the code responsible for the infobox window.
http://wojtas82.zrujnowane.pl/utf2.html#15/54.5027/18.4886/osm-rowerowe-piesze
And the code:
utfGrid2.on('mouseover', function(e){ info.update(e);}).on('mouseout', function(e){ info.update();})
utfGrid1.on('mouseover', function(e){ info.update(e);}).on('mouseout', function(e){ info.update();})
var info = L.control();
info.options.position = 'bottomleft';
info.onAdd = function (map) {
this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
this.update();
return this._div;
};
info.update = function (props) {
this._div.innerHTML = (props ?
'<img src="img/' + props.data.route +'_'+ props.data.osmc_color +'_'+ props.data.osmc_background +'_'+ props.data.osmc_foreground + '.png" ><br /> ' + "<b>" + props.data.name + "</b><br />" + 'Długość: ' + (props.data.distance ? props.data.distance : '') + ' km' + "<br />" + 'Opis szlaku: ' + (props.data.description ? props.data.description : '') : '');
};
I will be very greatful for help.
Thank you very much.
Have you tried using
L.popup for your popup? Something like
utfGrid1.on('click', function(e) {
if (e.data) {
L.popup()
.setLatLng(e.latlng)
.setContent(e ? '<img src="img/' + e.data.route + '_' + e.data.osmc_color + '_' + e.data.osmc_background + '_' + e.data.osmc_foreground + '.png" ><br /> ' + "<b>" + e.data.name + "</b><br />" + 'Długość: ' + (e.data.distance ? e.data.distance : '') + ' km' + "<br />" + 'Opis szlaku: ' + (e.data.description ? e.data.description : '')).openOn(map);
}
});

List facebook likes underneath every url

I was trying to find the best way to count number of likes for a facebook page url and after googling a lot and playing with the code, i have a code like the one given below. It outputs the likes, name of the page and then the link. I wish to know:
1. How can i use the html tag to convert the link into hyperlink so that I can have something like "Click here to visit"
2. How can monitor performance of 25+ fb_id on an hourly basis with a sorted order (descending) on likes
<?php
$fb_id = '36922302396';
$url = 'https://graph.facebook.com/' . urlencode($fb_id);
$result = json_decode( file_get_contents($url) );
printf("%s %s %s", $result->likes, $result->name, $result->link);
?>
Edited code as per solution provided
<?php
$fb_id = '36922302396';
$pic = 'https://www.facebook.com/' . urlencode($fb_id) . '/picture?type=square';
$url = 'https://graph.facebook.com/' . urlencode($fb_id);
$result = json_decode( file_get_contents($url) );
echo $result->likes , " " , $result->name , " " , "<a target='_blank' href=\"" . $result->link . "\" ><img src = $pic></a>";
?>
Thanks
For 1)
How about
<?php
$fb_id = '36922302396';
$url = 'https://graph.facebook.com/' . urlencode($fb_id);
$result = json_decode( file_get_contents($url) );
//printf("%s %s %s", $result->likes, $result->name, $result->link);
echo "Link";
?>
You can also use
Link
For 2)
If you know the Page's IDs, then you can just concatenate them to the following :
GET /?ids=40796308305,339150749455906&fields=id,name,likes,talking_about_count
The result looks like the following
{
"40796308305": {
"id": "40796308305",
"name": "Coca-Cola",
"likes": 88365218,
"talking_about_count": 635936
},
"339150749455906": {
"id": "339150749455906",
"name": "Pepsi",
"likes": 33321925,
"talking_about_count": 208761
}
}
For hourly stats, you need to setup your script via cron etc. and write the results to a database.

Using facebook javascript sdk to process fql query

I have just put implemented Facebook connect on my web-site using the JavaScript SDK. Now I would like to process an fql query.
So I have two questions:
Is it possible using only JavaScript fql as "SELECT id, name FROM user WHERE uid IN (SELECT uid1 FROM friends WHERE uid2=me())" ?
Because when I tried some PHP SDK code using the facebook doc
PHP:
$app_id = 'MY_ID';
$app_secret = 'MY_APP_SECRET';
$my_url = 'POST_AUTH_URL';
$code = $_REQUEST["code"];
$_REQUEST["code"] is quite normally not recognized and I don't know what is the "'POST_AUTH_URL'" because I didn't use the PHP SDK to process the Facebook-connect. Does anyone have an idea?
Using method: 'fql.query' is part of the deprecated REST API.
A better, future-proof way IMHO is to send your queries against the Graph API:
FB.api("/fql?q={your urlencoded query}", callback() { … } );
Using the JavaScript SDK you can easily execute an FQL query -
FB.api(
{
method: 'fql.query',
query: 'SELECT name FROM user WHERE uid=me()'
},
function(response) {
alert('Your name is ' + response[0].name);
}
);
Don't forget to request all the permissions you need before executing any queries...
Reference - https://developers.facebook.com/docs/reference/javascript/
Sorry I can't comment yet but to clarify this helpful answer; what worked for me was formatting the FQL API call the same way I would a Graph API call with {fields: "ex1,ex2"}:
var fqlRequest = "SELECT name FROM user WHERE uid = me()";
FB.api("/fql",{q:fqlRequest}, function(response){
// do cool stuff with response here
});
Note that I did NOT have to URL encode the string and it worked fine for me (I had used
encodeURI(fqlRequest) before and it returned an unexpected % error).
Also remember to quote literals if you use them:
var id = "1234567890";
var fqlRequest = "SELECT name FROM user WHERE uid = ' " + id + " ' ";

How do I order the friends list returned from the new Facebook Graph API?

You can get a list of friends of an authenticated user with:
https://graph.facebook.com/me/friends
Anyone have any idea how to order the list by user name? Because it doesn't by default. There's nothing in the documentation.
we do this in several apps just by sorting in javascript.
function sortByName(a, b) {
var x = a.name.toLowerCase();
var y = b.name.toLowerCase();
return ((x < y) ? -1 : ((x > y) ? 1 : 0));
}
var _friend_data = null
function lazy_load_friend_data(uid) {
if (_friend_data == null) {
FB.api('/me/friends', function(response) {
_friend_data = response.data.sort(sortByName);
}
)
}
}
Figured out a solution. Eventually, we'll probably be able to order graph results. For now, I'm just doing this (javascript). Assuming that I got "fb_uid" from my PHP session:
var friends = FB.Data.query("SELECT name, uid FROM user WHERE uid IN (SELECT uid2 FROM friend WHERE uid1={0}) ORDER BY name", parseInt(fb_uid));
friends.wait(function(rows){
console.log(rows);
});
I think the whole OpenGraph API is still in a bit of a transitional stage from FB Connect. In any case, I would just do a good old order-by query in FQL, which you can still use. I can't imagine it will be too hard to change once the open graph way of doing this gets established.
This very good tutorial shows you how to do it:
http://thinkdiff.net/facebook/php-sdk-graph-api-base-facebook-connect-tutorial/
$fql = "select name, hometown_location, sex, pic_square from user where uid=xxxxxxxxxxxxxxx";
$param = array(
'method' => 'fql.query',
'query' => $fql,
'callback' => ''
);
$fqlResult = $facebook->api($param);
What is the problem if you do it on caller side. That means, after you get all friends from that graph API, you can put all of them into a sorted data structure and then display all of them:)
Using FQL in one call.
SELECT uid, name FROM user WHERE uid IN
(SELECT uid2 FROM friend WHERE uid1 = me())
ORDER BY name ASC
for me a simple asort($friends); worked fine ;)
$friends = $facebook->api('me/friends');
foreach ($friends as $key=>$value) {
sort($value);
foreach ($value as $fkey=>$fvalue) {
echo "<img src='https://graph.facebook.com/".$fvalue[id]."/picture' width='50' height='50' title='".$fvalue[name]."' />";
}
}
Building off of #MainSocial's answer, but sorting by last then first name, instead of first name only:
function sortByName(a, b) {
var fn = function(x) { return x.name.toLowerCase(); };
var ln = function(x) { return x.last_name.toLowerCase(); };
if(ln(a) == ln(b)){
if(fn(a) == fn(b)) {
return 0;
}
return (fn(a) < fn(b)) ? -1 : 1;
}
return (ln(a) < ln(b)) ? -1 : 1;
}
function getFriendsList() {
FB.api('/me/friends', {fields: 'name,id,last_name'}, function(response) {
var friends = response.data.sort(sortByName);
for (i=0; i<friends.length; i++) {
$('body').append(friends[i].name + ' - ' + friends[i].id + '<br>');
}
});
}
getFriendsList()
private function _compareFacebookFriends($a, $b)
{
return strcasecmp($a['name'], $b['name']);
}
public function sortFacebookFriendsArray(&$array)
{
usort($array, '_compareFacebookFriends');
}
/* Add here $facebook's initialization. Use Facebook PHP SDK */
$fbFriends = $facebook->api('/me/friends');
sortFacebookFriendsArray($fbFriends);