Archive for the ‘Facebook’ Category

Upload photos on Facebook using PHP

Posted: February 14, 2013 in Facebook

If you have strived for the uploading photos on Facebook via your site, then you are at right place. On demand of my readers I have written this article to show how to upload images on Facebook via PHP. First of all you need to create a Facebook app. I will not tell you how to do that. Get the appId and secret code of your application from facebook. This appId and secret code is necessary to connect you site to the application on Facebook. This code uses the Facebook.php class that can be downloaded from here.

WebSpeaks.in | Upload images to Facebook

$appId, //your facebook application id
‘secret’ => $secret, //your facebook secret code
‘cookie’ => true
));

$user = $facebook->getUser();

if(is_null($facebook->getUser()))
{
header(“Location:{$facebook->getLoginUrl(array(‘req_perms’ => ‘user_status,publish_stream,user_photos’))}”);
exit;
}
/******************Configuration options***********************/

if($_SERVER[‘REQUEST_METHOD’] ==’POST’){
$img = realpath($_FILES[“pic”][“tmp_name”]);
// allow uploads
$facebook->setFileUploadSupport(“http://” . $_SERVER[‘SERVER_NAME’]);
// add a status message
$photo = $facebook->api(‘/me/photos’, ‘POST’,
array(
‘source’ => ‘@’ . $img,
‘message’ => ‘This photo was uploaded via http://www.WebSpeaks.in’
)
);

echo ‘

Click here to watch this photo on Facebook.

‘;
}
?>

Select a photo to upload on Facebook.

Select the image:

Advertisements
function fb_fan_count($facebook_name){
    // Example: https://graph.facebook.com/digimantra
    $data = json_decode(file_get_contents("https://graph.facebook.com/".$facebook_name));
    echo $data->likes;
}

Facebook Query Language( FQL)

Posted: December 28, 2012 in Facebook
Tags:

The FQL object enables running FQL queries using the Graph API. Facebook Query Language, or FQL, enables you to use a SQL-style interface to query the data exposed by the Graph API. It provides for some advanced features not available in the Graph API, including batching multiple queries into a single call.

You can execute FQL queries by fetching https://api.facebook.com/method/fql.query?query=QUERY. You can specify a response format as either XML or JSON with the format query parameter.

Queries are of the form SELECT [fields] FROM [table] WHERE [conditions]. Unlike SQL, the FQL FROM clause can contain only a single table. You can use the IN keyword in SELECT or WHERE clauses to do subqueries, but the subqueries cannot reference variables in the outer query’s scope. Your query must also be indexable, meaning that it queries properties that are marked as indexable in the documentation below.

For any query that takes a uid, you can pass me() to return the logged-in user. For example:

FQL to get details of the current logged in user by me() function

SELECT name FROM user WHERE uid = me() 
SELECT uid, name, pic_square FROM user WHERE uid = me()
OR uid IN (SELECT uid2 FROM friend WHERE uid1 = me())

Fql to get album id and details by album name

function get_album_id_by_album_name($album_name){//return array of data
        $fql            =   'SELECT aid, owner, name, object_id FROM album WHERE owner=me() and name="'.$album_name.'"';

                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql,
                'callback'  => ''
            );
            $fqlResult   =   $this->facebook->api($param);
	return $fqlResult;
}

FQL to get facebook user profile details

function get_user_profile_details($user_facebook_id){

		$fql    =   "SELECT name,pic_square,pic,uid 
FROM user  where	
 uid  =".$user_facebook_id;

                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql

            );
            $fqlResult   =   $this->facebook->api($param);
		return $fqlResult[0];
}

FQL to check the user is facebook application user

function check_is_app_user($facebook_user_id){//return 1 if the user is using the current application
	try{
	$user=$facebook_user_id;
        $fql    =   "select is_app_user from user where uid=" . $user;
            $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql,
                'callback'  => ''
            );

            $fqlResult   =   $this->facebook->api($param);

	if($fqlResult)
		return $fqlResult['0']['is_app_user'];
       else
                return 0;
        }
	 catch(Exception $o){
            d($o);
        }

}

FQL to get the tagged photos of facebook user and tag details,tag co-ordinates of user photos

function get_user_tagged_photos_details($user_facebook_id){

		$fql    =   "SELECT pid,text,xcoord,ycoord,created FROM photo_tag WHERE subject =".$user_facebook_id;

                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql

            );
            $fqlResult   =   $this->facebook->api($param);
		return $fqlResult[0];
}
function get_tagged_users_id_by_photoid($photo_id){

		$fql    =   "SELECT text FROM photo_tag WHERE pid =".$photo_id;

                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql

            );
            $fqlResult   =   $this->facebook->api($param);
		return $fqlResult[0];
}

pid-The ID of the photo being queried.
xcoord-The center of the tag’s horizontal position, measured as a floating-point percentage from 0 to 100, from the left edge of the photo.
ycoord-The center of the tag’s vertical position, measured as a floating-point percentage from 0 to 100, from the top edge of the photo.

FQL query to get user facebook notification filter by unread

function get_fb_notification_by_uid($user_id){

		$fql    =   "SELECT notification_id, sender_id,app_id,icon_url, title_html, body_html, href
FROM notification
WHERE recipient_id=".$user_id."
AND is_unread = 1
AND is_hidden = 0";
                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql

            );
            $fqlResult   =   $this->facebook->api($param);
		return $fqlResult[0];
}

sender_id-The user ID of the sender of the notification.
href-The URL associated with the notification. This is usually a location where the user can interact with the subject of the notification.
app_id-The ID of the application associated with the notification. This may be a third-party application or a Facebook application (for example, Wall).
is_unread-Indicates whether the notification has been marked as read. Use notifications.markRead to mark a notification as read.

FQL to get photos of my friends posted by date or week

function get_friends_photo_details($date){

		$fql    =   "SELECT pid, caption, aid, owner, link, src_big, src_small, created, modified FROM photo WHERE aid IN 
   (SELECT aid FROM album WHERE owner IN 
      (SELECT uid2 FROM friend WHERE uid1=me()) 
   ) 
AND created ."$date;

                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql

            );
            $fqlResult   =   $this->facebook->api($param);
		return $fqlResult[0];
}

function get_friends_photo_details_last_week(){

		$fql    =   "SELECT pid, caption, aid, owner, link, src_big, src_small, created, modified FROM photo WHERE aid IN 
   (SELECT aid FROM album WHERE owner IN 
      (SELECT uid2 FROM friend WHERE uid1=me()) 
   ) 
AND created > One_week_ago_in_unix_time ORDER BY created DESC";

                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql

            );
            $fqlResult   =   $this->facebook->api($param);
		return $fqlResult[0];
}

FQL to get photos by facebook albums

function get_photos_by_album_id($album_id){

if($album_id)
        $fql            =   'SELECT pid,src_big,owner,link,position,created,caption,src FROM photo WHERE aid="'.$album_id.'" ORDER BY created DESC LIMIT 0,6';

                $param  =   array(
                'method'    => 'fql.query',
                'query'     => $fql,
                'callback'  => ''
            );
            $fqlResult   =   $this->facebook->api($param);
		return $fqlResult;

}