friend list in facebook - php

I am trying to fetch friend list. I wrote following code..
$friends = $this->facebook->api('me/friends');
echo count($friends);
Answer was 1. (though it should have been 456). What am I doing wrong? Thanks for help.

The data structure returned by the API is different than you think.
Try echo count($friends['data']); instead.

Related

how to fetch a page's likes from fb by php

i want to make a social media audit tool and i want to get likes of a person's Fb page. Basically what i want is i want that person to enter his FB pages URL and then i want to fetch the likes of his page and echo it in my PHP page. Is there any way I can do that without using graph API or any API. I just want a simple piece of code.
I have searched many questions regarding my project on web and on StackOverflow as well but coudn't find what i wanted, at last, I am asking this question. Is there anyone who can help me regarding this?
Thanx in advance.
<?php
$file = "https://www.facebook.com/IntellectualIndies/?epa=SEARCH_BOX";
$data = file_get_contents($file);
preg_match_all ('~<div class=\'_4bl9\'>\s*(<div.*?</div>\s*)?(.*?)</div>~is', $data, $matches);
$content = $matches[1];
$total = count($content);
for($i=0; $i<$total; $i++){
echo $content[$i]."<br />";
}
?>
i tried this code.
Is there any way I can do that without using graph API or any API
No, scraping is not allowed on Facebook.
There is only one way to do this:
Apply for Page Public Content Access
Use the Graph API with the following endpoint/field: /page-id?fields=fan_count
API Reference with example code: https://developers.facebook.com/docs/graph-api/reference/page/

How to get the username of a person in php facebook sdk

I don't know I'm sounding stupid or not?
I am trying to find the username of a person in facebook through php. Is that at all possible??
Any help would be appreciated.. Thanks
Username is not available in API v2.0 and later. So no it is not possible get the username from a user id or the opposite.
Sorry I don't have enough rep to post it as comment.
#A'aqu the $request_url must be https instead of http and it should be more like https://graph.facebook.com/yourUID?access_token=yourAccessToken rather than just http://graph.facebook.com/yourUID.
Please update your answer
what data you have?
if you have uid you can find by:
http://graph.facebook.com/yourUID
example
http://graph.facebook.com/1503382632
if you want put to php you can get
<?php
$request_url ="http://graph.facebook.com/1503382632";
$requests = file_get_contents($request_url);
$fb_user = json_decode($requests);
echo $fb_user->username; //this will outpun username
?>

cant retrieve data from mysql db with php

Sorry for my bad English,
I cant retrieve record from mysql database, there's no error messages and nothing showing. The things is I want to retrieve data on a page with session using external php file. My table has data on it, I've inserted it with phpmyadmin. Here's the code :
UPDATE
I only work on php file now, and here the konek.php
<?php
error_reporting(E_ALL);
$konek=new mysqli('localhost','root','zxcvbnm','jumat') or die(mysqli_connect_error);
$selek=mysqli_query($konek,'select * from kategori');
while($baris=mysqli_fetch_array($selek)){
echo $baris['kodekat'].' '.$baris['namakat'];
echo '<br>';
}
if($konek){
echo 'koneksi ok';
}
$konek->close();
?>
it only shows the 'koneksi ok' word, is the while not processed?
thank you in advance
What are you trying to do with this line:
if($i<=mysql_fetch_array($selek)){
If you are trying to compare with the no. of data use:
if($i<=mysql_num_rows($selek)){
From personal experience, I had trouble with this traditional MySQL api.
I'll share this small PDO tutorial that got me over this mess, hope this helps you as much as it helped me.
http://code.tutsplus.com/tutorials/php-database-access-are-you-doing-it-correctly--net-25338
Try this:
<?php
$konek=mysqli_connect("localhost","root","zxcvbnm","jumat") or die(mysqli_error());
$selek=mysqli_query($konek,"select kodekat,namakat from kategori");
$i=0;
if(mysqli_num_rows($selek) > 0 ){
while($baris = mysqli_fetch_array($selek)){
$id = $baris["kodekat"];
$nmk = $baris["namakat"];
echo"kode: ".$id."nama:".$nmk.'<br/>';
}
}else{
echo 'No items in database';
}
mysqli_close($konek);
?>
I know the problem.
Yhe problem is, my database is empty, I'm so forgetfull, :)
sorry for the inconvenience, I'm sorry I'm sorry,
the code is fine, all of them, :)
and all of answers above, I'm sure it works,
its my faults, that's my database was empty in the first place,

Getting just number of facebook likes

I'm curious to use the facebook graph API as I don't like the simple like button with number of likes next to it. However I'm finding their documentation a bit confusing. I want to do this via PHP so I'm assuming I need the PHP SDK, is that right?
I'm looking at this page Graph API: Page however I don't understand how I would call the likes.
I'm not asking for someone to code this for me, just a little help in the right direction to understand how it works :)
Try this:
$json = #file_get_contents("http://graph.facebook.com/yourpage");
$json1 = json_decode($json,true);
$likes = $json1['likes'];
echo $likes;
This is pretty straightforward. Using the ID or the username of the page, access that
node via the Graph API:
PAGE_ID?fields=likes
In PHP would be something like:
$token_string = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id='.$appID.'&client_secret='.$app_secret.'&grant_type=client_credentials');
$likes_response = file_get_contents('https://graph.facebook.com/PAGE_ID?fields=likes&'.$token_string);
$likes_obj = json_decode($likes_response);
$likes = $likes_obj->likes;
echo 'Likes count for page: ' . $likes;

How to GET this value from JSON from Twitter API

Hey guys,
feel stupid for asking this question but I'm stuck and new with getting values from JSON.
In the JSON example of the statuses/mentions of the Twitter API: http://dev.twitter.com/doc/get/statuses/mentions
I'm trying to get the 'screen_name' value from with the 'user' directory/array piece (don't know the term). Heres what I'm using to pull values currently:
$lastmentions = $oauth->get('http://api.twitter.com/1/statuses/mentions.json');
$lastmentionsuser = $lastmentions[0]->user;
Thanks guys, Dex
This should work:
$screen_name = $lastmentionsuser->screen_name;
Woop Woop figured it!
It was:
$lastmmentionsuser = $lastmmentions[$i]->user->screen_name;

Categories