Monday, October 31, 2011

Facebook developers Map - Facebook api php from DreamWeaver

Facebook application development Facebook Api PhP - New.php

Let your Api users invite their friends to your Api. ... using Face book graph

New.php Code

<p class="style1">Redirecting ... </p>
<p>
<?php
$app_id = "118487369116";
$canvas_page = "http://evry1falls.freevar.com/test12/";
$message = "Would you like to join me in this great app?";
$requests_url = "http://www.facebook.com/dialog/apprequests?app_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page)
. "&message=" . $message;
$redirectUrlk = "https://www.facebook.com/dialog/oauth?client_id=118487369116&redirect_uri=http://evry1falls.freevar.com/
test12/index.php&state=5da7ce9f0201f209c7d699cb881c3b02&scope=
read_stream,friends_likes";
if (empty($_REQUEST["request_ids"])) {
echo("<script> top.location.href='" . $redirectUrlk . "'</script>");
} else {
echo "Request Ids: ";
print_r($_REQUEST["request_ids"]);
}
?>
view raw gistfile1.phtml hosted with ❤ by GitHub

Facebook developers Facebook Api PhP - try.php

Display The Name and the Photo of the current User of your Api ...

try.php Code

<?php
// Remember to copy files from the SDK's src/ directory to a
// directory in your application on the server, such as php-sdk/
require 'config.php';
$user_id = $facebook->getUser();
if($user_id) {
// We have a user ID, so probably a logged in user.
// If not, we'll get an exception, which we handle below.
try {
$user_profile = $facebook->api('/me','GET');
$user = $facebook->getUser();
?>
<p><b><span class="style3">Welcome</span> : <a href="http://www.facebook.com/
<?php echo $user; ?> " target="_parent"> <?php echo $user_profile['name']; ?> </a></b></p>
<p><img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
<?php
} catch(FacebookApiException $e) {
// If the user is logged out, you can have a
// user ID even though the access token is invalid.
// In this case, we'll get an exception, so we'll
// just ask the user to login again here.
$login_url = $facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '">login.</a>';
error_log($e->getType());
error_log($e->getMessage());
}
} else {
// No user, print a link for the user to login
$login_url = $facebook->getLoginUrl();
echo 'Please <a href="' . $login_url . '">login.</a>';
}
$redirectUrlk = "https://www.facebook.com/dialog/oauth?client_id=118487369116&redirect_uri=http://evry1falls.freevar.com/test12/index.php&state
=5da7ce9f0201f209c7d699cb881c3b02&scope=read_stream,friends_likes"; ?>
</p>
<p align="center"><a href = "<? $redirectUrlk ; ?> . "><strong>Back</strong></a>
view raw gistfile1.phtml hosted with ❤ by GitHub

FriendsPics Previous | Next New.php

Facebook application developer Facebook Api PhP - friendspics.php

Let your Api users to display the pics of their friends .

FriendsPics.Php

<?php
require 'config.php';
$friends = $facebook->api('/me/friends');
foreach ($friends as $key=>$value) {
echo '<font color=red><b>' . 'Oh, i have ' . count($value) . ' Friends'. '</font></b>';
echo '<hr />';
echo '<ol id="friends">';
foreach ($value as $fkey=>$fvalue) {
echo '<li><img src="https://graph.facebook.com/' . $fvalue[id] . '/picture"
title="' . $fvalue[name] . '"/></li>';
}
echo '</ol>';
}
$redirectUrlk = "https://www.facebook.com/dialog/oauth?client_id=118487369116&redirect_uri=http://evry1falls.freevar.com
/test12/index.php&state=5da7ce9f0201f209c7d699cb881c3b02&scope=
read_stream,friends_likes"; ?>
</p>
<p align="center"><a href = "<? $redirectUrlk ; ?> . "><strong>Back</strong></a>
view raw gistfile1.phtml hosted with ❤ by GitHub

friendlist Previous | Next try.php

Facebook application developer Facebook Api PhP - friendlist.php

Let your api users to display their friends list ..


friendlist.php Code

<?php
require 'config.php';
$canvas_auth = 'http://evry1falls.freevar.com/test12/';
$auth_url = $facebook->getLoginUrl(array(
'scope' => 'email,publish_stream',
'redirect_uri' => $canvas_auth,
// you could just redirect back to this index page though
));
// Get User ID
$user = $facebook->getUser();
if (empty($user)) {
// echo("<script> top.location.href='" . $auth_url . "'
$logoutUrl = $facebook->getLogoutUrl();
}
else {
// We may or may not have this data based on whether the user is logged in.
//
// If we have a $user id here, it means we know the user is logged into
// Facebook, but we don't know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
echo '<a href=http://www.evry1falls.freevar.com/test12/friendlist.php>' . 'Refresh' . '</a>';
}
}
}
$friends = $facebook->api('/me/friends');
$simple_array=$friends['data'];
foreach($simple_array as $key=> $value){
$freinds_id[]=$value['id'];
}
for($i=0;$i<count($freinds_id);$i++){
echo "<b>" . $freinds_id[$i]. "</b>" . "<BR>";
}
echo "<br />" . "You Have " . $i . " Friends";
$redirectUrlk = "https://www.facebook.com/dialog/oauth?client_id=118487369116&redirect_uri=http://evry1falls.freevar.com/test12/
index.php&state=5da7ce9f0201f209c7d699cb881c3b02&scope=read_stream,
friends_likes"; ?>
</p>
<p><a href = "<? $redirectUrlk ; ?> . ">Back</a>
view raw gistfile1.phtml hosted with ❤ by GitHub

feed.php Previous | Next friendspics.php

Facebook Api PhP - Feed.php

Let your API Users Post Messages to their wall ..

Feed.Php

<?php require 'main1.php'; ?>
<form name="" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label for="tt"><strong><br>
<br>
<br>
<br>
<br>
Status update using Graph API</strong></label>
<br />
<textarea id="tt" name="tt" cols="50" rows="5">Write
your status here and click 'Update My Status'</textarea>
<br />
<input name="submit" type="submit" value="Update My Status" />
</form>
<p>
<?php if (isset($statusUpdate)) { ?>
<br />
<strong style="color: red">Status Updated Successfully! Status id is
<?=$statusUpdate['id']?>
<?php }?></strong></p>
<?php $redirectUrlk = "https://www.facebook.com/dialog/oauth?client_id=118487369116&redirect_uri=http://evry1falls.freevar.com
/test12/index.php&state=5da7ce9f0201f209c7d699cb881c3b02&scope=
read_stream,friends_likes"; ?>
<a href = "<? $redirectUrlk ; ?> . ">Back</a>
view raw gistfile1.phtml hosted with ❤ by GitHub

Fbname.php Previous | Next FriendList.php

Facebook app development Facebook Api PhP - Fbname.php

The User Of Your App Friend's Names ... when a user logs into your app he could show all of his friends and know how many are they and thier (first name | last name) ....

Fbname.php Code

<?php
require 'config.php';
$friends = $facebook->api('/me/friends');
$simple_array=$friends['data'];
echo '<font color=white>';
foreach($simple_array as $key=> $value){
$freinds_name[]=$value['name'];
}
echo '<b><ol>';
for($i=0;$i<count($freinds_name);$i++){
echo "<li>" . $freinds_name[$i]. "</li>";
}
echo '</ol></b>';
echo "<br />" . "You Have " . $i . " Friends";
echo "<br />";
echo '</font>';
?>
<?php
$redirectUrlk = "https://www.facebook.com/dialog/oauth?client_id=118487369116&redirect_
uri=http://evry1falls.freevar.com/test12/index.php&state=
5da7ce9f0201f209c7d699cb881c3b02&scope=read_stream,friends_likes"; ?>
<center> <a href = "<? $redirectUrlk ; ?> . ">Back</a></center>
view raw gistfile1.phtml hosted with ❤ by GitHub

Config.php Previous || Next Feed.php

Wednesday, October 12, 2011

Facebook application developers Facebook Api PhP - Config.php

Config.php Code :
<?php
require 'facebook.php';
$config = array();
$config[‘appId’] = '118487369116';
$config[‘secret’] = 'e7baab9cae0bd29f2b39ba242d1029f8';
$config[‘fileUpload’] = false; // optional
$facebook = new Facebook($config);
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => '118487369116',
'secret' => 'e7baab9cae0bd29f2b39ba242d1029f8',
'cookie' => true,
'xfbml' => true,
));
?>
view raw gistfile1.phtml hosted with ❤ by GitHub
Index.php <=Previous || Next => Fbname.php

Facebook developers application Facebook Api PhP - Index.php

Index.Php Code :

<?php
require("config.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Testing</title>
</head>
<style>
html,
body {
margin:0;
padding:0;
height:auto;
background-color:#000066;
}
#container {
min-height:100%;
position:relative;
}
#header {
background:#0033FF;
padding:10px;
}
#body {
padding:10px;
padding-bottom:60px; /* Height of the footer */
}
#footer {
position:absolute;
bottom:0;
width:100%;
height:73px; /* Height of the footer */
background:#0033FF;
}
.style2 {
font-weight: bold;
color: #0000CC;
font-size: 36px;
}
.style3 {
color: #0000CC;
font-size: 18px;
}
</style>
<body>
<div id="container">
<div id="header">
<div align="center" class="style2">Testing</div>
</div>
<div id="body"><?php
# Let's see if we have an active session
$session = $facebook->getuser();
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$accesstoken=$session['access_token'];
} catch (FacebookApiException $e) {
error_log($e);
}
}
if($me)
{
// do what you have to do
echo "hello user";
echo "<p></p>";
echo "<p></p>";
echo "<p></p>";
}else {
$loginUrl = $facebook->getLoginUrl(
array(
'canvas' => 1,
'fbconnect' => 0,
'req_perms' => 'user_about_me,user_activities'
)
);
echo '<script>top.location="'.$loginUrl.'";</script>';
//echo '<fb:redirect url="' . $loginUrl . '" />';
//header('Location: '.$loginUrl);
}
?>
<a href="http://apps.facebook.com/ahmedsamir"><strong>Back</strong></a></div><p align="center">&nbsp;</p>
<div id="footer"> <hr align="center" color="#0000CC">
<p align="center" class="style14 style3"><strong>Copy Right &copy; Evry1falls </strong></p>
</div>
</div>
</body>
</html>
view raw gistfile1.phtml hosted with ❤ by GitHub

Main.php <=Previous || Next => Config.php

Monday, October 10, 2011

Facebook developers application Facebook Api Php - main.php

First,
Here is the Final Shape of your App Evry1falls

Final Look Of The Application Using (PHP)
Now,
1) main.php - Code
<?php
//facebook application
$fbconfig['appid' ] = "118487369116";
$fbconfig['secret'] = "e7baab9cae0bd29f2b39ba242d1029f8";
$fbconfig['baseurl'] = "http://evry1falls.freevar.com/test12/";
if (isset($_GET['request_ids'])){
//user comes from invitation
//track them if you need
}
$user = null; //facebook user uid
try{
require "facebook.php";
}
catch(Exception $o){
error_log($o);
}
// Create our Application instance.
$facebook = new Facebook(array(
'appId' => $fbconfig['appid'],
'secret' => $fbconfig['secret'],
'cookie' => true,
));
//Facebook Authentication part
$user = $facebook->getUser();
//$user_profile = $facebook->api('/me','GET');
// We may or may not have this data based
// on whether the user is logged in.
// If we have a $user id here, it means we know
// the user is logged into
// Facebook, but we don’t know if the access token is valid. An access
// token is invalid if the user logged out of Facebook.
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => 'email,offline_access,publish_stream,user_birthday,user_location,user_work_history,user_about_me,user_hometown',
'redirect_uri' => $fbconfig['baseurl']
)
);
$params = array( 'next' => 'http://evry1falls.freevar.com/index.php' );
$logoutUrl = $facebook->getLogoutUrl($params);
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
//you should use error_log($e); instead of printing the info on browser
d($e); // d is a debug function defined at the end of this file
$user = null;
}
}
//if user is logged in and session is valid.
if ($user){
//get user basic description
$userInfo = $facebook->api("/$user");
//update user's status using graph api
//http://developers.facebook.com/docs/reference/dialogs/feed/
if (isset($_GET['publish'])){
try {
$publishStream = $facebook->api("/$user/feed", 'post', array(
'message' => "Thanx For Using Evry1falls. :)",
'link' => 'http://evry1falls.freevar.com/test12/',
'picture' => 'http://1.bp.blogspot.com/_RWM4SJr3-U0/Sqxsjyn3xgI/AAAAAAAAAcQ/3kIdP5QBcfY/S45/evry1falls_t.jpg',
'name' => 'PHP Apps',
'description'=> 'Checkout PHP apps Toturials from evry1falls.blogspot.com. I found some of them are just awesome!'
)
);
//as $_GET['publish'] is set so remove it by redirecting user to the base url
} catch (FacebookApiException $e) {
d($e);
}
$redirectUrl = $fbconfig['baseurl'] . '/index.php?success=1';
header("Location: $redirectUrl");
}
//update user's status using graph api
//http://developers.facebook.com/docs/reference/dialogs/feed/
if (isset($_POST['tt'])){
try {
$statusUpdate = $facebook->api("/$user/feed", 'post', array('message'=> $_POST['tt']));
} catch (FacebookApiException $e) {
d($e);
}
}
}
function d($d){
echo '<pre>';
print_r($d);
echo '</pre>';
}
?>
view raw gistfile1.php hosted with ❤ by GitHub
- As you can see the main.php file holds the Variables from where other files will work through such as (Index.php) .... any question just post a comment !

Next - Index.php

Sunday, October 2, 2011

Facebook application development Fatal error: Uncaught OAuthException: An active access token must be used

This Topic aplies to SDK 3.x
Subject ( Fatal error: Uncaught OAuthException: An active access token must be used )
The Answer to this problem could be found here : Link
But let's discuss it, shall we!
- There are 4 reasons why Tokens get expire :
  1. The token expires after expiration time (2 hours is the default).
  2. The user changes his/her password which invalidates the access token.
  3. The user DE-authorizes your app.
  4. The user logs out of Facebook.
I will not explain the 4 reasons but i will just post the script solution :
<?php
$app_id = "YOUR_APP_ID";
$app_secret = "YOUR_APP_SECRET";
$my_url = "YOUR_POST_LOGIN_URL";
// known valid access token stored in a database
$access_token = "YOUR_STORED_ACCESS_TOKEN";
$code = $_REQUEST["code"];
// If we get a code, it means that we have re-authed the user
//and can get a valid access_token.
if (isset($code)) {
$token_url="https://graph.facebook.com/oauth/access_token?client_id=
. $app_id . "&redirect_uri=" . urlencode($my_url)
. "&client_secret=" . $app_secret
. "&code=" . $code . "&display=popup";
$response = file_get_contents($token_url);
$params = null;
parse_str($response, $params);
$access_token = $params['access_token'];
}
// Attempt to query the graph:
$graph_url = "https://graph.facebook.com/me?"
. "access_token=" . $access_token;
$response = curl_get_file_contents($graph_url);
$decoded_response = json_decode($response);
//Check for errors
if ($decoded_response->error) {
// check to see if this is an oAuth error:
if ($decoded_response->error->type== "OAuthException") {
// Retrieving a valid access token.
$dialog_url= "https://www.facebook.com/dialog/oauth?"
. "client_id=" . $app_id
. "&redirect_uri=" . urlencode($my_url);
echo("<script> top.location.href='" . $dialog_url
. "'</script>");
}
else {
echo "other error has happened";
}
}
else {
// success
echo("success" . $decoded_response->name);
echo($access_token);
}
// note this wrapper function exists in order to circumvent PHP’s
//strict obeying of HTTP error codes. In this case, Facebook
//returns error code 400 which PHP obeys and wipes out
//the response.
function curl_get_file_contents($URL) {
$c = curl_init();
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($c, CURLOPT_URL, $URL);
$contents = curl_exec($c);
$err = curl_getinfo($c,CURLINFO_HTTP_CODE);
curl_close($c);
if ($contents) return $contents;
else return FALSE;
}
?>
view raw gistfile1.php hosted with ❤ by GitHub
- If there is any question, just post a comment.
- i will get back here to try to explain the codes .

google me (evry1falls)