Facebook API - Help with introduction

Started on the old forum in July 2010 · view the original in the archive · old links redirect here

8 replies · 1,520 views · started 16 years ago · 1 min read

3 participants
Mysterio Lead · 630 posts #1

Hello guys,

Anyone can help with an introduction on how to use Facebook API? An example on how to get status, or get someone's wall, would be cool!

mysterio.al - programming is a functional art

CreativityKills Lead · 833 posts #2

Download the php sdk. Register ur app, configure it wit ur keys. Request perms (publish_stream) then instantiate a fb object

$facebook = new Facebook(array('api_key'=>'sh.it','secret'=>'fu.ck','cookies'=>true));
$session=$facebook->getSession();
$fbme=false;
try{
$fbme=$facebook->api('/me');
}catch(FacebookApiException $e){
die($e);
}

if($fbme){
try{
$facebook->api('me/feed','post',array('message'=>'MY STATUS MESSAGE','cb'=>''));
}catch(FacebookApiException $e){
die('Couldnt update status. Facebook said:'.$e);
}
}else{
header('Location: '.$facebook->getLoginUrl('req_perms'=>'publish_stream'));
exit;
}

Added after 2 minutes:

Getting status requires read_stream permission. After getting the permission, run $status=$facebook->api('/me/status'); i think.

Mysterio Lead · 630 posts #3

Good, thank you (I will try it)!

And what if we need to get someone's wall? I am asking for different actions to see how it works!

mysterio.al - programming is a functional art

Mysterio Lead · 630 posts #5

I was looking at official Facebook API page and I started using Graph API. This looks faster (I don't know if better).

To get someone's wall, just type "http: // graph.facebook.com/(user-id)/feed". This step is passed, but the problem now is how to style the result, as what is being showed from that URL is: {"data":[{"id":"1670158248_133190916717388","from":{"name":"Ervis Mysterio","id":"1670158248"},"message":"Hello All"... (continues till end of wall)

Can I suggest me any way of styling it?

mysterio.al - programming is a functional art

CreativityKills Lead · 833 posts #6

You already ave d result. It was JSON decoded into an array. So just use it as u wud any array.

$fbme=$facebook->api('/me/feed?limit=10&fields=from,id,message'); /// use limit parameter when requesting data thats plenty e.g wall posts.
foreach($fbme['data'] as $data){
echo $data['from']['name'].': '.$data['message'].'<br/>';
}

Get it? Fbook sends a json encoded reply, the api decodes and changes it to arrays. Just work with that.

Mysterio Lead · 630 posts #7

So there is no way to display feed as html on a website different from fb, without having an app, api key and secret key?

If no, how should this application be, and can a single application be used in different actions (in different websites for example with different purposes for different fb users)?

p.s. Sorry for lot of questions, you are not obligated to answer everytime!

mysterio.al - programming is a functional art

rukiya Lead · 569 posts #8

Mysterio3 wrote: So there is no way to display feed as html on a website different from fb, without having an app, api key and secret key?

If no, how should this application be, and can a single application be used in different actions (in different websites for example with different purposes for different fb users)?

p.s. Sorry for lot of questions, you are not obligated to answer everytime!

You cant use facebook api without api key and secret code. You will need to add codes for different actions in different pages of web sites using facebook api.

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close