Permalink
Browse files

add facebook src

  • Loading branch information...
dennis
dennis committed Oct 11, 2012
1 parent 348e012 commit 9896ee122b307b45229a4cfe905ce1e29e2586b0
@@ -0,0 +1 @@
+/coverage/
@@ -0,0 +1,5 @@
+language: php
+php:
+ - 5.3
+ - 5.4
+script: phpunit --stderr --bootstrap tests/bootstrap.php tests/tests.php
@@ -0,0 +1,28 @@
+Facebook PHP SDK (v.3.0.0)
+==========================
+
+The new PHP SDK (v3.0.0) is a major upgrade to the older one (v2.2.x):
+
+- Uses OAuth authentication flows instead of our legacy authentication flow
+- Consists of two classes. The first (class BaseFacebook) maintains the core of the upgrade, and the second one (class Facebook) is a small subclass that uses PHP sessions to store the user id and access token.
+
+If you’re currently using the PHP SDK (v2.2.x) for authentication, you will recall that the login code looked like this:
+
+ $facebook = new Facebook(…);
+ $session = $facebook->getSession();
+ if ($session) {
+ // proceed knowing you have a valid user session
+ } else {
+ // proceed knowing you require user login and/or authentication
+ }
+
+The login code is now:
+
+ $facebook = new Facebook(…);
+ $user = $facebook->getUser();
+ if ($user) {
+ // proceed knowing you have a logged in user who's authenticated
+ } else {
+ // proceed knowing you require user login and/or authentication
+ }
+
@@ -0,0 +1,22 @@
+{
+ "name": "facebook/php-sdk",
+ "description": "Facebook PHP SDK",
+ "keywords": ["facebook", "sdk"],
+ "type": "library",
+ "homepage": "https://github.com/facebook/facebook-php-sdk",
+ "license": "Apache2",
+ "authors": [
+ {
+ "name": "Facebook",
+ "homepage": "https://github.com/facebook/facebook-php-sdk/contributors"
+ }
+ ],
+ "require": {
+ "php": ">=5.2.0",
+ "ext-curl": "*",
+ "ext-json": "*"
+ },
+ "autoload": {
+ "classmap": ["src"]
+ }
+}
@@ -0,0 +1,102 @@
+<?php
+/**
+ * Copyright 2011 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
+ * not use this file except in compliance with the License. You may obtain
+ * a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+require '../src/facebook.php';
+
+// Create our Application instance (replace this with your appId and secret).
+$facebook = new Facebook(array(
+ 'appId' => '344617158898614',
+ 'secret' => '6dc8ac871858b34798bc2488200e503d',
+));
+
+// Get User ID
+$user = $facebook->getUser();
+
+// 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;
+ }
+}
+
+// Login or logout url will be needed depending on current user state.
+if ($user) {
+ $logoutUrl = $facebook->getLogoutUrl();
+} else {
+ $loginUrl = $facebook->getLoginUrl();
+}
+
+// This call will always work since we are fetching public data.
+$naitik = $facebook->api('/naitik');
+
+?>
+<!doctype html>
+<html xmlns:fb="http://www.facebook.com/2008/fbml">
+ <head>
+ <title>php-sdk</title>
+ <style>
+ body {
+ font-family: 'Lucida Grande', Verdana, Arial, sans-serif;
+ }
+ h1 a {
+ text-decoration: none;
+ color: #3b5998;
+ }
+ h1 a:hover {
+ text-decoration: underline;
+ }
+ </style>
+ </head>
+ <body>
+ <h1>php-sdk</h1>
+
+ <?php if ($user): ?>
+ <a href="<?php echo $logoutUrl; ?>">Logout</a>
+ <?php else: ?>
+ <div>
+ Login using OAuth 2.0 handled by the PHP SDK:
+ <a href="<?php echo $loginUrl; ?>">Login with Facebook</a>
+ </div>
+ <?php endif ?>
+
+ <h3>PHP Session</h3>
+ <pre><?php print_r($_SESSION); ?></pre>
+
+ <?php if ($user): ?>
+ <h3>You</h3>
+ <img src="https://graph.facebook.com/<?php echo $user; ?>/picture">
+
+ <h3>Your User Object (/me)</h3>
+ <pre><?php print_r($user_profile); ?></pre>
+ <?php else: ?>
+ <strong><em>You are not Connected.</em></strong>
+ <?php endif ?>
+
+ <h3>Public profile of Naitik</h3>
+ <img src="https://graph.facebook.com/naitik/picture">
+ <?php echo $naitik['name']; ?>
+ </body>
+</html>
@@ -0,0 +1,59 @@
+<?php
+
+require '../src/facebook.php';
+
+$facebook = new Facebook(array(
+ 'appId' => '344617158898614',
+ 'secret' => '6dc8ac871858b34798bc2488200e503d',
+));
+
+// See if there is a user from a cookie
+$user = $facebook->getUser();
+
+if ($user) {
+ try {
+ // Proceed knowing you have a logged in user who's authenticated.
+ $user_profile = $facebook->api('/me');
+ } catch (FacebookApiException $e) {
+ echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
+ $user = null;
+ }
+}
+
+?>
+<!DOCTYPE html>
+<html xmlns:fb="http://www.facebook.com/2008/fbml">
+ <body>
+ <?php if ($user) { ?>
+ Your user profile is
+ <pre>
+ <?php print htmlspecialchars(print_r($user_profile, true)) ?>
+ </pre>
+ <?php } else { ?>
+ <fb:login-button></fb:login-button>
+ <?php } ?>
+ <div id="fb-root"></div>
+ <script>
+ window.fbAsyncInit = function() {
+ FB.init({
+ appId: '<?php echo $facebook->getAppID() ?>',
+ cookie: true,
+ xfbml: true,
+ oauth: true
+ });
+ FB.Event.subscribe('auth.login', function(response) {
+ window.location.reload();
+ });
+ FB.Event.subscribe('auth.logout', function(response) {
+ window.location.reload();
+ });
+ };
+ (function() {
+ var e = document.createElement('script'); e.async = true;
+ e.src = document.location.protocol +
+ '//connect.facebook.net/en_US/all.js';
+ document.getElementById('fb-root').appendChild(e);
+ }());
+ </script>
+ </body>
+</html>
@@ -0,0 +1,86 @@
+Facebook PHP SDK (v.3.2.0)
+==========================
+
+The [Facebook Platform](http://developers.facebook.com/) is
+a set of APIs that make your app more social.
+
+This repository contains the open source PHP SDK that allows you to
+access Facebook Platform from your PHP app. Except as otherwise noted,
+the Facebook PHP SDK is licensed under the Apache Licence, Version 2.0
+(http://www.apache.org/licenses/LICENSE-2.0.html).
+
+
+Usage
+-----
+
+The [examples][examples] are a good place to start. The minimal you'll need to
+have is:
+
+ require 'facebook-php-sdk/src/facebook.php';
+
+ $facebook = new Facebook(array(
+ 'appId' => 'YOUR_APP_ID',
+ 'secret' => 'YOUR_APP_SECRET',
+ ));
+
+ // Get User ID
+ $user = $facebook->getUser();
+
+To make [API][API] calls:
+
+ 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;
+ }
+ }
+
+Login or logout url will be needed depending on current user state.
+
+ if ($user) {
+ $logoutUrl = $facebook->getLogoutUrl();
+ } else {
+ $loginUrl = $facebook->getLoginUrl();
+ }
+
+[examples]: http://github.com/facebook/facebook-php-sdk/blob/master/examples/example.php
+[API]: http://developers.facebook.com/docs/api
+
+
+Tests
+-----
+
+In order to keep us nimble and allow us to bring you new functionality, without
+compromising on stability, we have ensured full test coverage of the SDK.
+We are including this in the open source repository to assure you of our
+commitment to quality, but also with the hopes that you will contribute back to
+help keep it stable. The easiest way to do so is to file bugs and include a
+test case.
+
+The tests can be executed by using this command from the base directory:
+
+ phpunit --stderr --bootstrap tests/bootstrap.php tests/tests.php
+
+
+Contributing
+===========
+For us to accept contributions you will have to first have signed the
+[Contributor License Agreement](https://developers.facebook.com/opensource/cla).
+
+When commiting, keep all lines to less than 80 characters, and try to
+follow the existing style.
+
+Before creating a pull request, squash your commits into a single commit.
+
+Add the comments where needed, and provide ample explanation in the
+commit message.
+
+
+Report Issues/Bugs
+===============
+[Bugs](https://developers.facebook.com/bugs)
+
+[Questions](http://facebook.stackoverflow.com)
Oops, something went wrong.

0 comments on commit 9896ee1

Please sign in to comment.