protected function _finish($code, $originalRedirectUri) { $url = RequestUtil::buildUri($this->appInfo->getHost()->getApi(), "1/oauth2/token"); $params = array("grant_type" => "authorization_code", "code" => $code, "redirect_uri" => $originalRedirectUri, "locale" => $this->userLocale); $curl = RequestUtil::mkCurlWithoutAuth($this->clientIdentifier, $url); // Add Basic auth header. $basic_auth = $this->appInfo->getKey() . ":" . $this->appInfo->getSecret(); $curl->addHeader("Authorization: Basic " . base64_encode($basic_auth)); $curl->set(CURLOPT_POST, true); $curl->set(CURLOPT_POSTFIELDS, RequestUtil::buildPostBody($params)); $curl->set(CURLOPT_RETURNTRANSFER, true); $response = $curl->exec(); if ($response->statusCode !== 200) { throw RequestUtil::unexpectedStatus($response); } $parts = RequestUtil::parseResponseJson($response->body); if (!array_key_exists('token_type', $parts) or !is_string($parts['token_type'])) { throw new Exception_BadResponse("Missing \"token_type\" field."); } $tokenType = $parts['token_type']; if (!array_key_exists('access_token', $parts) or !is_string($parts['access_token'])) { throw new Exception_BadResponse("Missing \"access_token\" field."); } $accessToken = $parts['access_token']; if (!array_key_exists('uid', $parts) or !is_string($parts['uid'])) { throw new Exception_BadResponse("Missing \"uid\" string field."); } $userId = $parts['uid']; if ($tokenType !== "Bearer" && $tokenType !== "bearer") { throw new Exception_BadResponse("Unknown \"token_type\"; expecting \"Bearer\", got " . Client::q($tokenType)); } return array($accessToken, $userId); }
private function getAppInfo($appId) { try { $appinfo = new AppInfo(); return $appinfo->getAppInfo($appId); } catch (Exception $e) { return ""; } }
/** * Constructor. * * @param string $key * {@link getKey()} * @param string $secret * {@link getSecret()} */ function __construct($key, $secret) { AppInfo::checkKeyArg($key); AppInfo::checkSecretArg($secret); $this->key = $key; $this->secret = $secret; }
/** * Constructor. * * @param AppInfo $appInfo * See {@link getAppInfo()} * @param string $clientIdentifier * See {@link getClientIdentifier()} * @param null|string $userLocale * See {@link getUserLocale()} */ function __construct($appInfo, $clientIdentifier, $userLocale = null) { AppInfo::checkArg("appInfo", $appInfo); Client::checkClientIdentifierArg("clientIdentifier", $clientIdentifier); Checker::argStringNonEmptyOrNull("userLocale", $userLocale); $this->appInfo = $appInfo; $this->clientIdentifier = $clientIdentifier; $this->userLocale = $userLocale; }
/** * 使用code换取access_token */ public static function code_to_token($appid, $code) { $app_info = AppInfo::query($appid); $app_secret = $app_info['AppSecret']; $line = SnsNetwork::makeRequest("https://api.weixin.qq.com/sns/oauth2/access_token", "appid={$appid}&secret={$app_secret}&code={$code}&grant_type=authorization_code", '', 'get', 'https'); if (!$line["result"]) { Log::trace("code换取token调度失败"); return; } return json_decode($line['msg'], true); }
function fromFacebook($facebook) { try { $data = $facebook->api('/' . $this->id); } catch (FacebookApiException $e) { return false; } $this->name = $data['name']; $this->imageurl = $data['picture']; $this->latitude = $data['location']['latitude']; $this->longitude = $data['location']['longitude']; if (!$this->imageurl) { $this->imageurl = AppInfo::getUrl('/images/unknown.gif'); } return true; }
require_once 'classes.php'; require_once 'utils.php'; require_once 'database.php'; require_once 'sdk/src/facebook.php'; $db = new Database(new PDO(AppInfo::getDatabaseDSN(), null, null, array(PDO::ATTR_PERSISTENT => true))); $facebook = new Facebook(array('appId' => AppInfo::appID(), 'secret' => AppInfo::appSecret())); $user_id = $facebook->getUser(); if ($user_id) { try { // Fetch the viewer's basic information $myfb = $facebook->api('/me'); } catch (FacebookApiException $e) { // If the call fails we check if we still have a user. The user will be // cleared if the error is because of an invalid accesstoken if (!$facebook->getUser()) { header('Location: ' . AppInfo::getUrl($_SERVER['REQUEST_URI'])); exit; } } $authenticated = true; } else { $authenticated = false; } if (isset($myfb['error_code'])) { die('Error connecting to Facebook: ' . $myfb['error_code'] . ': ' . $myfb['error_msg']); } $myself = new Student($user_id); if (!$myself->fromDatabase($db)) { $myself->fromFacebook($facebook); } // get my high school data
method: 'feed', name: 'Silver Rhapsody Jewelry Design Giveaway', description: "I entered the @SilverRhapsodyDesigns Giveaway to win a TBD.", link: 'http://www.facebook.com/SilverRhapsodyDesigns', picture: '<?php echo AppInfo::getUrl('/images/fbthumb.jpg'); ?> ' }; FB.ui(args, null); }; FB.init({ appId: '<?php echo AppInfo::appID(); ?> ', channelUrl: '//<?php echo $_SERVER["HTTP_HOST"]; ?> /channel.html', status: true, cookie: true, xfbml: true, logging: true }); FB.Canvas.setAutoGrow(); };
<?php error_reporting(E_ALL); ini_set("display_errors", 1); // Loading SLIM require 'slim/Slim/Slim.php'; \Slim\Slim::registerAutoloader(); $app = new Slim\Slim(); require_once "src/AppInfo.php"; require_once "src/Utils.php"; // LOADING FACEBOOK require_once 'sdk/src/facebook.php'; $facebook = new Facebook(array('appId' => AppInfo::appID(), 'secret' => AppInfo::appSecret(), 'sharedSession' => true, 'trustForwarded' => true)); $app->get('/hello/:name', function ($name) use($app) { $app->render('show.php', array('title' => 'Sahara')); echo "Hello, {$name}"; }); $app->get('/', function ($name = "Demo app Open graph") use($app, $facebook) { $user_id = $facebook->getUser(); //$app_info = $facebook->api('/'. AppInfo::appID()); //$app_name = Utils::idx($app_info, 'name', ''); $app->render('main.php', array('user_id' => $user_id, "title" => "DEMO APP FB OG")); }); $app->get("/maps/streetview", function () use($app, $facebook) { $user_id = $facebook->getUser(); $app->render('map_streetview.php', array('user_id' => $user_id, "title" => "Street View")); }); $app->get('/info', function () { phpinfo(); }); $app->run();
?> "> <input type="hidden" name="reportee_name" value="<?php print he($_REQUEST['reportee_name']); ?> " /> <?php clarifyReportee($search_results, array('description' => "Please clarify who you're trying to find stories about.", 'next' => $next_search_results_url)); ?> </form> <?php } else { if ($_REQUEST['submit'] || $_REQUEST['submit_clarification']) { ?> <p>No information on this person could be found. Would you like to <a href="<?php print he(AppInfo::getUrl("/reports.php?action=new&reportee_id={$reportee_id}")); ?> ">share some</a>?</p> <?php } } } } } ?> <form id="pat-find-report-form" method="post" action="<?php print "{$_SERVER['PHP_SELF']}?action=lookup"; ?> "> <fieldset><legend>Reportee details</legend> <?php
<?php require_once 'lib/pat-fb-init.php'; if (!$me) { header('Location: ' . AppInfo::getUrl()); exit; } $prefs = $me->getPreferences(); if ($_REQUEST['submit']) { $new_prefs = array('notify_on_same_reportee' => $_REQUEST['notify_on_same_reportee'] ? true : false, 'notify_on_friend_reported' => $_REQUEST['notify_on_friend_reported'] ? true : false, 'user_timezone_name' => in_array($_REQUEST['user_timezone_name'], DateTimeZone::listIdentifiers()) ? $_REQUEST['user_timezone_name'] : 'UTC'); if ($me->savePreferences($new_prefs)) { $prefs = $new_prefs; } } include 'templates/header.php'; ?> <section id="MainContent"> <form> <?php if ($prefs === $new_prefs) { ?> <div class="FlashMessage"><p>Your preferences have been saved.</p></div><?php } ?> <p>Customize how <?php print he($FBApp->getAppName()); ?> behaves for you.</p> <fieldset><legend>Notification preferences</legend> <p><strong>Send me a Facebook notification whenever…</strong></p> <p><label><input type="checkbox" id="" name="notify_on_same_reportee"
?> </title> <link rel="stylesheet" href="stylesheets/screen.css" media="screen"> <!-- These are Open Graph tags. They add meta data to your --> <!-- site that facebook uses when your content is shared --> <!-- over facebook. You should fill these tags in with --> <!-- your data. To learn more about Open Graph, visit --> <!-- 'https://developers.facebook.com/docs/opengraph/' --> <meta property="og:title" content=""/> <meta property="og:type" content=""/> <meta property="og:url" content=""/> <meta property="og:image" content=""/> <meta property="og:site_name" content=""/> <?php echo '<meta property="fb:app_id" content="' . AppInfo::appID() . '" />'; ?> <!-- START Edited by Ravi Desai at 05-11-2011 17:16:56 --> <script language="JavaScript"> var months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"); var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); var days = new Array("S", "M", "T", "W", "T", "F", "S"); today = new getToday(); var element_id; var temp;
die(json_encode(array('success' => 0, 'message' => 'Cannot load school.', 'request' => $request_message_specific))); } if ($college->latitude == 0 || $college->longitude == 0) { die(json_encode(array('success' => 0, 'message' => 'Cannot locate school.', 'request' => $request_message_specific))); } // new school, add to database $college->updateDatabase($db); } // add friend to hs $db->addAssociation($friend, $curhs->id, AssociationTypes::HighSchool); // add friend to college $db->addAssociation($friend, $college->id, AssociationTypes::College); // add concentrations if (!$concentrations) { foreach ($concentrations as $fb_concentration) { $concentration = new Concentration($fb_concentration['id']); if (!$concentration->fromDatabase($db)) { // try getting cached data from db // if we fail, this concentration doesn't exist yet $concentration->fromFacebook($facebook); $concentration->updateDatabase($db); } $db->addAssociation($friend, $concentration->id, AssociationTypes::Concentration); } } // add student $friend->year = $curyear; $friend->updateDatabase($db); $feed = array('link' => AppInfo::getPageUrl("/?school=" . $curhs->id . "&year=" . $curyear), 'picture' => 'http://home.web2go.com/basic/nfpi/3.90/ql/0/0/lg?' . $college->imageurl, 'name' => $curhs->name . ' class of ' . $curyear . ' College Map', 'description' => 'Your friend ' . $myself->name . ' added you to ' . $college->name . ' on the college map for ' . $curhs->name . ' class of ' . $curyear); $school = array('id' => $college->id, 'name' => $college->name, 'image' => $college->imageurl, 'location' => array('latitude' => (int) $college->latitude, 'longitude' => (int) $college->longitude)); echo json_encode(array('success' => 1, 'message' => 'Friend added.', 'feed' => $feed, 'school' => $school));
} } // This fetches some things that you like . 'limit=*" only returns * values. // To see the format of the data you are retrieving, use the "Graph API // Explorer" which is at https://developers.facebook.com/tools/explorer/ $likes = idx($facebook->api('/me/likes?limit=4'), 'data', array()); // This fetches 4 of your friends. $friends = idx($facebook->api('/me/friends?limit=4'), 'data', array()); // And this returns 16 of your photos. $photos = idx($facebook->api('/me/photos?limit=16'), 'data', array()); // Here is an example of a FQL call that fetches all of your friends that are // using this app $app_using_friends = $facebook->api(array('method' => 'fql.query', 'query' => 'SELECT uid, name FROM user WHERE uid IN(SELECT uid2 FROM friend WHERE uid1 = me()) AND is_app_user = 1')); } // Fetch the basic info of the app that they are using $app_info = $facebook->api('/' . AppInfo::appID()); $app_name = idx($app_info, 'name', ''); ?> <!DOCTYPE html> <html xmlns:fb="http://ogp.me/ns/fb#"> <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# object: http://ogp.me/ns/object#"> <meta property="fb:app_id" content="YOUR_APP_ID" /> <meta property="og:type" content="object" /> <meta property="og:url" content="Put your own URL to the object here" /> <meta property="og:title" content="Sample Object" /> <meta property="og:image" content="https://s-static.ak.fbcdn.net/images/devsite/attachment_blank.png" /> <!-- <script src="/javascript/track.js" type="text/javascript"></script> --> <title>CAAT example: Actors across a Path and Interpolators</title> <link rel="stylesheet" href="/style/demo.css">
Flight::ok($object); } catch (Exception $exception) { Flight::error($exception); } }); Flight::route('PUT /v1/main/appinfo/@id', function ($id) { try { $object = AppInfo::update($id); Flight::ok($object); } catch (Exception $exception) { Flight::error($exception); } }); Flight::route('DELETE /v1/main/appinfo/@id', function ($id) { try { $object = AppInfo::delete($id); Flight::ok($object); } catch (Exception $exception) { Flight::error($exception); } }); //============================================================================= //AppLog //============================================================================= Flight::route('GET /v1/main/applog', function () { try { $array = AppLog::selectAll(); Flight::ok($array); } catch (Exception $exception) { Flight::error($exception); }
public function removewhitelistAction() { $array_of_params = $this->_request->getParams(); try { //var_dump($array_of_params['appid'],$array_of_params['u']);die(); $appserver = new AppInfo(); $appserver->removeIdFromWhitelist($array_of_params['appid'], $array_of_params['u']); $this->_forward('whitelist'); return; } catch (Exception $e) { var_dump($e); die; } }
echo he(idx($basic, 'name')); ?> </strong></h1> <p class="tagline"> Applikasi <a href="<?php echo he(idx($app_info, 'link')); ?> " target="_top"><?php echo he($app_name); ?> </a> di Facebook <div id="share-app"> <ul> <li> <a href="#" class="facebook-button" id="postToWall" data-url="<?php echo AppInfo::getUrl(); ?> "> <span class="plus">Share ke dinding</span> </a> </li> <li> <a href="#" class="facebook-button apprequests" id="sendRequest" data-message="Test this awesome app"> <span class="apprequests">Ajakin Teman</span> </a> </li> </ul> </div> </p>
public function tranxbyappsummarysubmitAction() { $array_of_params = $this->_request->getParams(); if (!isset($array_of_params['fromdate']) || $array_of_params['fromdate'] == '' || !isset($array_of_params['todate']) || $array_of_params['todate'] == '' || !isset($array_of_params['appid'])) { $array_of_params['fromdate'] = date('Y-m-d', strtotime("now -1 day")); $array_of_params['todate'] = date('Y-m-d', strtotime("now -1 day")); $array_of_params['radiogroup'] = 1; $array_of_params['appid'] = 0; } $this->view->param = $array_of_params; $fromdate = $array_of_params['fromdate'] . ' 00:00:00'; $todate = $array_of_params['todate'] . ' 23:59:59'; $appIDs = array(); $appserver = new AppInfo(); if ($array_of_params['appid'] == '0') { $appIDs = $this->view->uApps; } else { $appIDs[$array_of_params['appid'] . ''] = $appserver->getAppName($array_of_params['appid']); } $reporter = new Reporter(); $result = array(); $keys = array_keys($appIDs); foreach ($keys as $appID) { $subresult = array(); switch ($array_of_params['radiogroup']) { case 1: $subresult = $reporter->summaryDaily($appID, $fromdate, $todate); break; case 2: $subresult = $reporter->summary($appID, $fromdate, $todate); break; } if (count($subresult) > 0 && $subresult[0]['appID'] != null) { $result[] = $subresult; } } if ($array_of_params['export'] == 'csv') { $this->exportCSV($result); die; } else { $this->view->data = $result; $this->view->frmSearch = $this->view->render('index/app_tranxbyapp_summary.phtml'); $this->view->container = $this->view->render('index/index.phtml'); } }
$result = pg_query_params($db->getHandle(), 'SELECT DISTINCT reporter_id FROM incidents WHERE reportee_id = $1 AND reporter_id <> $2', array($report->reportee_id, $report->reporter_id)); // Check those other people's notification preference. while ($row = pg_fetch_assoc($result)) { $usr = new PATFacebookUser($FB, $row['reporter_id']); $prefs = $usr->getPreferences(); // If their notification preference is on, if ($prefs['notify_on_same_reportee']) { $report->setReader($usr); if ($report->isVisible()) { // send each of them a notification. $FB->setAccessToken(getFacebookAppToken()); $FB->api("/{$usr->getId()}/notifications", 'post', array('template' => 'More information was shared about someone you previously shared about; click here to read the statement.', 'href' => "reports.php?action=lookup&id={$rid}")); } } } header('Location: ' . AppInfo::getUrl($_SERVER['PHP_SELF'] . "?action=lookup&id={$rid}")); exit; } } } ?> <section id="MainContent"> <h1>Share</h1> <?php if (!isset($_REQUEST['submit']) && !isset($_REQUEST['submit_clarification']) || isset($_REQUEST['submit_clarification']) && $reportee_id || isset($report)) { ?> <form id="pat-report-form" method="post" action="<?php print "{$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}"; ?> "> <fieldset><legend>Details (<a href="<?php
/** * Authenticates the current viewer of the app, prompting them to login and * grant permissions if necessary. For more information, check the * 'https://developers.facebook.com/docs/authentication/' * * @return app access token if login is successful */ public static function login($redirect) { $app_id = AppInfo::appID(); $app_secret = AppInfo::appSecret(); $home = AppInfo::getHome(); // Scope defines what permissions that we are asking the user to grant. // In this example, we are asking for the ability to publish stories // about using the app, access to what the user likes, and to be able // to use their pictures. You should rewrite this scope with whatever // permissions your app needs. // See https://developers.facebook.com/docs/reference/api/permissions/ // for a full list of permissions $scope = 'user_likes,user_photos,user_photo_video_tags'; session_start(); $code = $_REQUEST["code"]; // If we don't have a code returned from Facebook, the first step is to get // that code if (empty($code)) { // CSRF protection - for more information, look at 'Security Considerations' // at 'https://developers.facebook.com/docs/authentication/' $state = md5(uniqid(rand(), TRUE)); setcookie(AppInfo::appID() . '-fb-app', $state, $expires = 0, $path = "", $domain = "", $secure = "", $httponly = true); // Now form the login URL that you will use to authorize your app $authorize_url = "https://www.facebook.com/dialog/oauth?client_id={$app_id}" . "&redirect_uri={$home}&state=" . $state . "&scope={$scope}"; // Now we redirect the user to the login page echo "<script> top.location.href='" . $authorize_url . "'</script>"; return false; // Once we have that code, we can now request an access-token. We check to // ensure that the state has remained the same. } else { if ($_REQUEST['state'] === $_COOKIE[AppInfo::appID() . '-fb-app']) { $ch = curl_init("https://graph.facebook.com/oauth/access_token"); curl_setopt($ch, CURLOPT_POSTFIELDS, "client_id={$app_id}&redirect_uri={$home}&client_secret={$app_secret}" . "&code={$code}&scope={$scope}"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $response = curl_exec($ch); // Once we get a response, we then parse it to extract the access token parse_str($response, $params); $token = $params['access_token']; return $token; // In the event that the two states do not match, we return false to signify // that something has gone wrong during authentication } else { echo "States do not match. CSRF?"; return false; } } }
<?php header('Access-Control-Allow-Origin:*'); require_once 'lib/SnsNetwork.php'; require_once 'lib/SnsSigCheck.php'; require_once 'include/log.php'; require_once 'include/app_info.php'; require_once 'include/wx.php'; $appid = $_REQUEST['appid']; $cmd = $_REQUEST['cmd']; if (!$appid) { die('请指定AppID'); } if (!AppInfo::query($appid)) { die('AppID尚未配置'); } $data = null; switch ($cmd) { case 'sign': // 获取分享的签名信息 $data = WX::get_sign($appid, $_REQUEST['url']); break; default: die("未知指令"); } echo json_encode($data);
function reportListItem($report) { $title = $report->report_title ? $report->report_title : 'untitled story'; ?> <li><img alt="" src="https://graph.facebook.com/<?php print he($report->reportee_id); ?> /picture" /><a rel="bookmark" href="<?php print he(AppInfo::getUrl('/reports.php') . "?action=lookup&id={$report->id}"); ?> ">"<span class="pat-report-title"><?php print he($title); ?> </span>", shared on <?php print he(date('F j, Y', strtotime($report->report_date))); ?> </a>.</li> <?php }
require_once 'facebook/src/facebook.php'; // Load our own libraries. require 'pat-fb/PATFacebookUser.class.php'; require 'pat-fb/PATIncident.class.php'; require 'pat-fb/template_functions.inc.php'; $FB = new Facebook(array('appId' => AppInfo::appID(), 'secret' => AppInfo::appSecret(), 'trustForwarded' => true)); $user_id = $FB->getUser(); if ($user_id) { try { // Fetch the viewer's basic information $me = new PATFacebookUser($FB); $me->loadFriends('id,name,gender,picture.type(square),bio,installed'); $my_prefs = $me->getPreferences(); date_default_timezone_set($my_prefs['user_timezone_name']); } catch (FacebookApiException $e) { error_log('Failed to set global variable $me.'); error_log(serialize($e)); // If the call fails we check if we still have a user. The user will be // cleared if the error is because of an invalid accesstoken if (!$FB->getAccessToken()) { header('Location: ' . AppInfo::getUrl($_SERVER['REQUEST_URI'])); exit; } } } // Some global variables. $FBApp = new AppInfo($FB->api('/' . AppInfo::appID())); $db = new PATFacebookDatabase(); $db->connect(psqlConnectionStringFromDatabaseUrl()); // Links to "help" screens. define('DOCUMENTATION_URL_BASE', 'https://github.com/meitar/pat-facebook/wiki');
<li>We cache the following information about you in our databases: your name, your Facebook ID, your high school graduation year, your school rank (if you provided it), an link to your profile picture, and your education history (from your profile).</li> <li>All information we store are for caching purposes only (so the site will load faster), and we will NEVER sell your information.</li> <li>If you choose to remove yourself via the "Delete" button, all the information we have about you will be wiped from our databases.</li> <li>If you add your friend to the map, this applies to them too.</li> </ul> </div> </div> <div id="credits_modal" class="modal hide fade"> <div class="modal-header"> <a href="#" class="close">×</a> <h3>Credits</h3> </div> <div class="modal-body"> <p>This has been Yifan's attempt at making a real web app. He designed, coded, and tested this site by himself, so please excuse the quality. You can find his site <a href="http://yifan.lu/" target="_blank">here</a>. UI elements are courtesy of <a href="http://ckrack.github.com/fbootstrapp/" target="_blank">Fbootstrapp</a>. Javascript code is powered by <a href="http://jquery.com/" target="_blank">jQuery</a>. The app icon is from <a href="http://www.famfamfam.com/lab/icons/silk/" target="_blank">FamFamFam silk icon set</a>. Thanks to anyone forgotten. Bug reports should be directed <a href="https://www.facebook.com/CollegesMapCommunity" target="_blank">to the creator directly</a>. If you don't know him… well, your problem will never be solved.</p> </div> </div> </div> <div id="content"> <div class="messagebox" id="message" style="display:none;"></div> <div class="map" id="map_canvas"></div> <div class="comments"> <div class="fb-comments" data-href="<?php echo he(AppInfo::getPageUrl('/?school=' . $curhs->id . '&year=' . $curyear)); ?> " data-num-posts="4"></div> </div> </div> <footer>Made with love by <a href="http://yifan.lu/" target="_blank">Yifan Lu</a> • <a href="#" data-controls-modal="privacy_modal" data-backdrop="true" data-keyboard="true">Privacy Policy</a> • <a href="#" data-controls-modal="credits_modal" data-backdrop="true" data-keyboard="true">Credits</a> • <a href="https://www.facebook.com/CollegesMapCommunity" target="_blank">Community</a></footer> </body> </html>