function facebookBroadcastNotice($notice) { $facebook = getFacebook(); $flink = Foreign_link::getByUserID($notice->profile_id, FACEBOOK_SERVICE); $fbuid = $flink->foreign_id; if (isFacebookBound($notice, $flink)) { $status = null; // Get the status 'verb' (prefix) the user has set try { $prefix = $facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX, $fbuid); $status = "{$prefix} {$notice->content}"; } catch (FacebookRestClientException $e) { common_log(LOG_ERR, $e->getMessage()); return false; } // Okay, we're good to go! try { $facebook->api_client->users_setStatus($status, $fbuid, false, true); updateProfileBox($facebook, $flink, $notice); } catch (FacebookRestClientException $e) { common_log(LOG_ERR, $e->getMessage()); return false; // Should we remove flink if this fails? } } return true; }
function facebookBroadcastNotice($notice) { $facebook = getFacebook(); $flink = Foreign_link::getByUserID($notice->profile_id, FACEBOOK_SERVICE); if (isFacebookBound($notice, $flink)) { // Okay, we're good to go, update the FB status $status = null; $fbuid = $flink->foreign_id; $user = $flink->getUser(); $attachments = $notice->attachments(); try { // Get the status 'verb' (prefix) the user has set // XXX: Does this call count against our per user FB request limit? // If so we should consider storing verb elsewhere or not storing $prefix = trim($facebook->api_client->data_getUserPreference(FACEBOOK_NOTICE_PREFIX, $fbuid)); $status = "{$prefix} {$notice->content}"; $can_publish = $facebook->api_client->users_hasAppPermission('publish_stream', $fbuid); $can_update = $facebook->api_client->users_hasAppPermission('status_update', $fbuid); if (!empty($attachments) && $can_publish == 1) { $fbattachment = format_attachments($attachments); $facebook->api_client->stream_publish($status, $fbattachment, null, null, $fbuid); common_log(LOG_INFO, "Posted notice {$notice->id} w/attachment " . "to Facebook user's stream (fbuid = {$fbuid})."); } elseif ($can_update == 1 || $can_publish == 1) { $facebook->api_client->users_setStatus($status, $fbuid, false, true); common_log(LOG_INFO, "Posted notice {$notice->id} to Facebook " . "as a status update (fbuid = {$fbuid})."); } else { $msg = "Not sending notice {$notice->id} to Facebook " . "because user {$user->nickname} hasn't given the " . 'Facebook app \'status_update\' or \'publish_stream\' permission.'; common_log(LOG_WARNING, $msg); } // Finally, attempt to update the user's profile box if ($can_publish == 1 || $can_update == 1) { updateProfileBox($facebook, $flink, $notice); } } catch (FacebookRestClientException $e) { $code = $e->getCode(); $msg = "Facebook returned error code {$code}: " . $e->getMessage() . ' - ' . "Unable to update Facebook status (notice {$notice->id}) " . "for {$user->nickname} (user id: {$user->id})!"; common_log(LOG_WARNING, $msg); if ($code == 100 || $code == 200 || $code == 250) { // 100 The account is 'inactive' (probably - this is not well documented) // 200 The application does not have permission to operate on the passed in uid parameter. // 250 Updating status requires the extended permission status_update or publish_stream. // see: http://wiki.developers.facebook.com/index.php/Users.setStatus#Example_Return_XML remove_facebook_app($flink); } else { // Try sending again later. return false; } } } return true; }
<img src="<?php getImage(); ?> " alt="<?php getName(); ?> " height="100" width="100"> </div> <div id=showInfo> <b><?php getName(); ?> </b> <ul> <li><a href="<?php getFacebook(); ?> " target="_blank"><img src="images/facebook-logo-3.png" alt="Facebook link" height="35" width="35"></a> </li> <li><a href="<?php getTwitter(); ?> " target="_blank"><img src="images/Twitter-logo-2012.png" alt="Twitter link" height="25" width="30"></a> </li> <li><a href="<?php getMixcloud(); ?> " target="_blank" ><img src="images/mixcloud.png" alt="Mixcloud link" height="33" width="33"></a> </li> </ul> ""<?php getTagline(); ?> ""
function getProfilePicURL($fbuid) { $facebook = getFacebook(); $url = null; try { $fqry = 'SELECT pic_square FROM user WHERE uid = %s'; $result = $facebook->api_client->fql_query(sprintf($fqry, $fbuid)); if (!empty($result)) { $url = $result[0]['pic_square']; } } catch (Exception $e) { common_log(LOG_WARNING, "Facebook client failure requesting profile pic!"); } return $url; }
function updateProfileBox($facebook, $flink, $notice, $user) { $facebook = getFacebook(); $fbaction = new FacebookAction($output = 'php://output', $indent = null, $facebook, $flink); $fbuid = $flink->foreign_id; common_debug('FacebookPlugin - Attempting to update profile box with ' . "content from notice {$notice->id} for {$user->nickname} ({$user->id}), " . "Facebook UID: {$fbuid}"); $fbaction->updateProfileBox($notice); common_debug('FacebookPlugin - finished updating profile box for ' . "{$user->nickname} ({$user->id}) Facebook UID: {$fbuid}"); }
function showAppLink() { $this->facebook = getFacebook(); $app_props = $this->facebook->api_client->Admin_getAppProperties(array('canvas_name', 'application_name')); $this->app_uri = 'http://apps.facebook.com/' . $app_props['canvas_name']; $this->app_name = $app_props['application_name']; $this->out->elementStart('a', array('id' => 'facebook_statusnet_app', 'href' => $this->app_uri)); $this->out->text($this->app_name); $this->out->elementEnd('a'); }
/** * Handle post * * Disconnects the current Facebook user from the current user's account * * @return void */ function handlePost() { // CSRF protection $token = $this->trimmed('token'); if (!$token || $token != common_session_token()) { $this->showForm(_m('There was a problem with your session token. ' . 'Try again, please.')); return; } if ($this->arg('disconnect')) { $user = common_current_user(); $flink = Foreign_link::getByUserID($user->id, FACEBOOK_CONNECT_SERVICE); $result = $flink->delete(); if ($result === false) { common_log_db_error($user, 'DELETE', __FILE__); $this->serverError(_m('Couldn\'t delete link to Facebook.')); return; } try { // Clear FB Connect cookies out $facebook = getFacebook(); $facebook->clear_cookie_state(); } catch (Exception $e) { common_log(LOG_WARNING, 'Facebook Connect Plugin - ' . 'Couldn\'t clear Facebook cookies: ' . $e->getMessage()); } $this->showForm(_m('You have disconnected from Facebook.'), true); } else { $this->showForm(_m('Not sure what you\'re trying to do.')); return; } }
function getFacebookFields($fb_uid, $fields) { try { $facebook = getFacebook(); $infos = $facebook->api_client->users_getInfo($fb_uid, $fields); if (empty($infos)) { return null; } return reset($infos); } catch (Exception $e) { common_log(LOG_WARNING, "Facebook client failure when requesting " . join(",", $fields) . " on uid " . $fb_uid . " : " . $e->getMessage()); return null; } }
<div class="large-3 large-centered columns"> <div class="login-box"> <div class="row"> <div class="larger-1 columns logoPlanty"> <img src="img/logo.png" alt="Planty Logo"/> </div> <div class="large-12 columns"> <form> <div class="row"> <div class="large-12 large-centered columns fb"> <!--<a href="<?php echo getFacebook()->getLoginUrl(); ?> "><img src="../img/fb.png"/></a>--> <a class="button expand buttonFb" href="<?php echo getFacebook()->getLoginUrl(); ?> ">Sign Up With Facebook</a> </div> </div> <div class="row"> <div class="large-12 large-centered columns"> <a class="button expand" href="" value="">Sign Up With Email </a> </div> <div class="large-12 large-centered columns centerAlign logInLinks"> <a href="">Log in</a> </div> </div> <div class="row"> <div class="large-12 large-centered columns centerAlign back2Intro"> <a href="intro.php">Back to Intro</a>
<?php if (get_sub_field('section_name')) { ?> <h2><?php echo strtoupper(get_sub_field('section_name')); ?> </h2> <?php } ?> <div class="social-feed"> <div class="feed-container"> <?php $network = get_sub_field('social_network'); if ($network == 'facebook') { $social_post = getFacebook(ot_get_option('facebook')); $suffix = "fb"; } elseif ($network == 'twitter') { $social_post = getTwitter(ot_get_option('twitter')); $suffix = "twitter"; } for ($i = 0; $i < 3; $i++) { ?> <?php echo '<a href="' . $social_post[$i]['url'] . '">'; ?> <div class="social-block"> <div class="social-date"> <p><span class='glyphicon glyphicon-<?php echo $suffix; ?>
<?php // Get FB token and send back DB content // vendor dir has all the 3rd party php libs; on heroku you can put this in .gitignore since heroku installs all these on its side; // same thing happens on google app engine require './vendor/autoload.php'; require './config.php'; require './common.php'; $accessToken = (string) $_GET["token"]; // send back (this is a GET call from client, so whatever you output from here goes there) // echo "$accessToken"; syslog(LOG_INFO, "FB token: " . $accessToken); $fb = getFacebook($appId, $appSecret); // To extend an access token, you can make use of the OAuth2Client. // OAuth 2.0 client handler $oAuth2Client = $fb->getOAuth2Client(); // Exchanges a short-lived access token for a long-lived one $longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($accessToken)->getValue(); //echo $longLivedAccessToken; /** store stuff **/ // Use Google Cloud Storage (not Cloud DataStore, which is a DB). GCS is unstructured data. // Use this to create buckets and manage: https://console.cloud.google.com/storage/browser?project=zouk-event-calendar // Code below is generally out of date with documentation. See source in vendor/google/... for correct usage // I created 1 bucket through web interface (can also be created programmatically). Inside this bucket will be many files. // /** // * Google Cloud Storage API request to retrieve the list of buckets in your project. // */ // $projectId = 'zouk-event-calendar'; // $buckets = $storage->buckets->listBuckets($projectId); // // foreach ($buckets['items'] as $bucket) {
<?php //define('ABSPATH', '/'); require "ncstate-social-sdk.php"; // Facebook example echo "<h2>Facebook</h2>"; try { $fb = getFacebook('ncstate', 1); } catch (Exception $e) { echo $e->getMessage(); } foreach ($fb as $post) { echo "<strong>" . date('M d, y', $post['time']) . "</strong><br/>"; echo $post['message'] . "<br/>"; echo "<a href=" . $post['url'] . ">" . $post['url'] . "</a><br/><br/>"; } // Twitter Example echo "<br/><br/><br/><br/><h2>Twitter</h2>"; try { $twitter = getTwitter("ncstate", 2); } catch (Exception $e) { echo $e->getMessage(); } foreach ($twitter as $tweet) { $output = "<p><strong>" . date('M d, y', $tweet['time']) . "</strong><br/>" . $tweet['description']; if ($tweet['media'][0]->media_url) { $output .= "<br/><img src='" . $tweet['media'][0]->media_url . "' />"; } $output .= "</p>"; echo $output; }
<?php session_start(); require 'inc/includes.php'; $facebook = getFacebook(); $token = $facebook->getAccessToken(); $url = 'https://www.facebook.com/logout.php?next=http://' . getRemoteHostname() . '&access_token=' . $token; logoutUser(); header('Location: ' . $url);
function getFBUserProfile() { return getFacebook()->api('/me?fields=name,email,picture.width(120).height(120)'); }