include_once 'facebook_conf.php';
include_once 'facebookapi_php5_restlib.php';
$auth_token = $_REQUEST['auth_token'];
if ($_REQUEST['logout']) {
    // clear the cookies
    setcookie('session_key');
    setcookie('uid');
} else {
    $session_key = $_COOKIE['session_key'];
    $uid = $_COOKIE['uid'];
}
if (!$auth_token && !$session_key) {
    header('Location: ' . $config['login_url']);
    return;
}
$client = new FacebookRestClient($config['rest_server_addr'], $config['api_key'], $config['secret'], $session_key, false);
if (!$session_key) {
    $expires = time() + 3600;
    $session_info = $client->auth_getSession($auth_token);
    $client->session_key = $session_info['session_key'];
    $uid = $session_info['uid'];
    /* You should not blindly trust cookies to provide valid authentication 
     * information since they are transmitted in the clear and can be easily 
     * modified (especially not for the user id).  We encourage you to use your 
     * own more advanced session management system, we merely do this as an 
     * example.  */
    setcookie('session_key', $session_info['session_key'], $expires);
    setcookie('uid', $uid, $expires);
}
$my_profile = $client->users_getInfo(array($uid), $profile_field_array);
$my_name = $my_profile[$uid]['name'];
Example #2
0
<?
ob_start();
include "../../default_config.php"; // for api keys
include "facebookapi_php5_restlib.php";

session_start();

if ($_GET['newsession_req']) {
  $_SESSION['session_key'] = NULL;
}
$session_key = @$_SESSION['session_key'];
$uid = @$_SESSION['uid'];

$client = new FacebookRestClient($facebok_api_key, $facebook_api_secret);
//$client->server_addr = 'http://api.facebook.com/restserver.php';
$client->server_addr = 'http://pokemon.broadbandmechanics.com/fb_api/restserver.php';
//$client->debug = 1;
if ($session_key) $client->session_key = $session_key;

if (!$session_key) {
  $token = @$_GET['auth_token'];

  if ($token) {
    echo "<p>ok, i have an auth token: $token</p>";
    
      $r = $client->auth_getSession($token);
    
    $session_key = $_SESSION['session_key'] = $r['session_key'];
    $uid = $_SESSION['uid'] = $r['uid'];
  }
  else {
 /**
  * For every invocation we need to figure where the call
  * should go.  For example a rating service should be redirected to the
  * rating service.
  *
  * @param unknown_type $method
  * @param unknown_type $params
  * @return unknown
  */
 public function call_method($method, $params)
 {
     $stack = explode(".", $method);
     $this->setNamespace($stack[0]);
     $result = parent::call_method($method, $params);
     return $result;
 }
Example #4
0
/*
de
-------------------------
Array
(
    [session_key] => 16e38d489ee23fdf8f11758c-706418514
    [uid] => 706418514
    [expires] => 0
    [secret] => 56bc805265036e5b174c2cbd87aa6269
)
16e38d489ee23fdf8f11758c-706418514

german
------------------------
Array
(
    [session_key] => 4d46faabe92e5b921d17bdcf-706418514
    [uid] => 706418514
    [expires] => 0
    [secret] => 6f3f0bdc5efa2ff894eaeff7d02d7511
)
4d46faabe92e5b921d17bdcf-706418514
*/
$fb = new FacebookRestClient("edb10ef1662aa239e336dfd66f838d6f", "a65c24679d7b3897c5d345cf436bf24d");
$testtoken = "035X35";
// Replace this value with your Token Value
$result = $fb->call_method('facebook.auth.getSession', array('auth_token' => $testtoken, 'generate_session_secret' => true));
echo "<br /><pre>";
print_r($result);
echo $session_key = $result['session_key'];
echo "post on facebook wall";
Example #5
0
<?php

require_once 'facebook-client/facebook.php';
require_once 'facebook-client/facebookapi_php5_restlib.php';
$appapikey = '{YOUR API KEY HERE}';
$appsecret = '{YOUR APPLICATION SECRET KEY HERE}';
// do this after validation
$userid = $_REQUEST['fb_sig_user'];
$sKey = $_REQUEST['fb_sig_session_key'];
if ($_REQUEST['action'] == "getName") {
    try {
        $fbClient = new FacebookRestClient($appapikey, $appsecret, $sKey);
    } catch (FacebookRestClientException $ex) {
        // Handle Exception
    }
    $userInfo = $fbClient->fql_query("SELECT name FROM user WHERE uid={$userid}");
    $userName = $userInfo[0]['name'];
    // $userName now contains user's name.
}
// | For help with this library, contact developers-help@facebook.com          |
// +---------------------------------------------------------------------------+
//
include_once 'include/config.php';
include_once 'include/facebookapi_php5_restlib.inc.php';
session_start();
if (!array_key_exists('auth_token', $_GET)) {
    header('Location: ' . $config['login_url']);
    exit;
} else {
    $auth_token = $_REQUEST['auth_token'];
}
try {
    // Create our client object.
    // This is a container for all of our static information.
    $client = new FacebookRestClient($config['rest_server_addr'], $config['api_key'], $config['secret'], null, false);
    // The required call: Establish session
    // The session key is saved in the client lib for the whole PHP instance.
    $session_info = $client->auth_getSession($auth_token);
    $uid = $session_info['uid'];
    // Get the entire user profile.
    $user_profile = $client->users_getInfo($uid, $profile_field_array);
    $user_name = $user_profile[0]['name'];
    // Get five of the user's friends.
    $friends_array = array_slice($client->friends_get(), 0, 5);
    // See if these two friends know each other.
    if (isset($friends_array[0]) && isset($friends_array[1])) {
        $friend_info = $client->friends_areFriends($friends_array[0], $friends_array[1]);
    }
    // Get all of this user's photo albums.
    $albums = $client->photos_getAlbums($uid, null);
 public function dashboard_publishActivity($activity, $image = null, $st1 = null, $st2 = null, $st3 = null)
 {
     $uuid = $this->m_an->gen_kt_dashboard_publishActivity_link($activity, $st1, $st2, $st3);
     $r = parent::dashboard_publishActivity($activity, $image);
     if (!empty($r)) {
         $this->m_an->kt_dashboard_publish_activity($uuid, $st1, $st2, $st3);
     }
     return $r;
 }
 public function &feed_publishUserAction_vo($template_bundle_id, $template_data, $target_ids = array(), $body_general = '', $campaign_name, $story_size = FacebookRestClient::STORY_SIZE_ONE_LINE)
 {
     $msg_info_array = $this->m_an->m_ab_testing_mgr->get_selected_msg_info($campaign_name);
     $page_info = $this->m_an->m_ab_testing_mgr->get_selected_page_info($campaign_name);
     $msg_id = $msg_info_array[0];
     $msg_text = $msg_info_array[2];
     $st1 = $this->m_an->format_kt_st1($campaign_name);
     $st2 = $this->m_an->format_kt_st2($msg_id);
     $st3 = $this->m_an->format_kt_st3($page_info[0]);
     $this->m_an->gen_feed_publishUserAction($template_data, $template_bundle_id, $st1, $st2, $st3, $msg_text);
     $r = parent::feed_publishUserAction($template_bundle_id, $template_data, $target_ids, $body_general, $story_size);
     if ($r != null) {
         $this->m_an->kt_user_action_feed_send($this->m_an->get_fb_param('user'), $template_bundle_id, $st1, $st2, $st3);
     }
     return $r;
 }
 /** 
 	int  fb_sig_user  The uid of the person who is uninstalling your application (e.g. 609143784)  
 	string  fb_sig_session_key  The session_key originally given to your application for the user who is uninstalling the application. This parameter did not appear in the latest requests.  
 	string  fb_sig_api_key  The api_key of your application that is being uninstalled.  
 	int  fb_sig_added  n/a  
 	string  fb_sig  
 */
 private function getContext(FacebookRestClient $client, RingsideSocialSession $network_session)
 {
     $api_key = $client->api_key;
     $session_key = $client->session_key;
     $uid = $client->users_getLoggedInUser();
     $social_session_key = $network_session->getSessionKey();
     $names = $client->users_getInfo($uid, "first_name");
     $name = $names[0];
     $user_name = trim($name['first_name']);
     return "fb_sig_user={$uid}&user_name={$user_name}&fb_sig_api_key={$api_key}&fb_sig_session_key={$session_key}&social_session_key={$social_session_key}";
 }
Example #10
0
function fbapp_mod_blog_post_publish($blog_id, $id, $title)
{
    global $ssc_site_url, $ssc_database, $ssc_site_path;
    require_once 'facebook.php';
    $api_key = "9c476aaa4b1654c09ede303a7d140a36";
    $secret_key = ssc_var_get('fbapp_blog_secret', '');
    if ($secret_key == '') {
        ssc_add_message(SSC_MSG_CRIT, "Facebook user secret key has not been set up yet!");
        return;
    }
    $session_key = ssc_var_get('fbapp_blog_session', '');
    if ($session_key == '') {
        ssc_add_message(SSC_MSG_CRIT, "Facebook user session key has not been set yet!");
        return;
    }
    $client = new FacebookRestClient($api_key, $secret_key, $session_key);
    if (!$client->users_getLoggedInUser()) {
        ssc_add_message(SSC_MSG_CRIT, "Unable to get userid");
        return;
    }
    $dbres = $ssc_database->query("SELECT body FROM #__blog_post WHERE id = %d LIMIT 1", $id);
    if (!$dbres) {
        ssc_add_message(SSC_MSG_CRIT, "Unable to retrieve posted item from database?!");
        return;
    }
    if (!($data = $ssc_database->fetch_assoc($dbres))) {
        ssc_add_message(SSC_MSG_CRIT, "Unable to retrieve posted item from database?!");
        return;
    }
    $img = null;
    // Extract the first image
    $i = strpos($data['body'], '[[img');
    if ($i !== false) {
        // Some basic error checking for a valid tag
        $j = strpos($data['body'], ']]', $i);
        $k = strpos($data['body'], '[[', $i + 3);
        if ($j !== false && ($j < $k || $k === FALSE)) {
            $path = explode("|", substr($data['body'], $i, $j - $i));
            if (count($path) > 1) {
                $path = $path[1];
                // Now match it up to the right path
                if (strpos($path, "://") === false) {
                    if ($path[0] == "/") {
                        $path = substr($path, 1);
                    }
                    // Relative path
                    if (file_exists($ssc_site_path . "/images/{$path}.jpg") || file_exists($ssc_site_path . "/images/{$path}.png") || file_exists($ssc_site_path . "/images/{$path}")) {
                        // Default to image directory base-dir
                        $img = $ssc_site_url . "/images/{$path}";
                    } elseif (file_exists($ssc_site_path . "/{$path}") || file_exists($ssc_site_path . "/{$path}.jpg") || file_exists($ssc_site_path . "/{$path}.png")) {
                        // Relative to site root instead
                        $img = $ssc_site_url . '/' . $path;
                    }
                }
            }
        }
    }
    // Hackish - TODO later for multiple blog paths, non-root based
    $uri = $ssc_site_url . "/id/{$id}";
    //$result = $client->feed_publishUserAction(30881549425, array("title"=>$title, "uri"=>$uri), '', '', 2);
    $attachment = array('name' => $title, 'href' => $uri, 'caption' => 'A blog post has just been made');
    if ($img != null) {
        $attachment['media'] = array(array('type' => 'image', 'src' => $img, 'href' => $uri));
    }
    $action_links = array(array('text' => 'Read this post', 'href' => $uri));
    $target_id = null;
    //array();
    $uid = null;
    $result = $client->stream_publish(" has been blogging", $attachment, $action_links, $target_id, $uid);
    if ($result) {
        ssc_var_set('fbapp_blog_lastid', $id);
    } else {
        ssc_add_message("Unable to post to FB");
    }
}