Giter Site home page Giter Site logo

rizs820 / social Goto Github PK

View Code? Open in Web Editor NEW

This project forked from definitely246/social

0.0 1.0 0.0 287 KB

A preconfigured setup of oauth plugins that piggybacks off of the very popular lusitanian/phpoauthlib. The project uses a facade for oauth and api's to the most popular social websites (facebook, twitter, google, etc) and the goal of this project is to have oauth setup within 10 minutes of installing this package.

License: Other

PHP 100.00%

social's Introduction

What the heck is this Social package?

We've stopped working on this thing.

Unforunately the underlying package lusitanian/oauth has a few issues. We've upgraded to the latest version but there may be issues. :( We don't have time to really put in the work to make this package production worthy, so please use at your own risk.

If you'd like to contribute, please put in a pull request.

You can add new providers in pull requests if you'd like. Just browse around the code some.

Goal

This package's goal is to quickly integrate oauth and social media sites like facebook, twitter and google into your laravel 4 application.

We do this with a preconfigured setup of oauth plugins that piggybacks off of the very popular lusitanian/phpoauthlib. The project uses a facade for oauth and api's to the most popular social websites (facebook, twitter, google, etc) and within minutes after installing this package to have oauth integrated.

Installation

Begin by installing this package through Composer. Edit your project's composer.json file to require codesleeve/social.

It might look something like:

  "require": {
    "laravel/framework": "4.0.*",
  	"codesleeve/social": "dev-master"
  }

Next, update Composer from the Terminal:

    composer update

Once this operation completes add the service provider. Open app/config/app.php, and add a new item to the providers array.

    'Codesleeve\Social\SocialServiceProvider'

And put in the Social facade under the aliases array in app/config/app.php.

     'Social' => 'Codesleeve\Social\Social',

Lastly generate a package config that you can work with.

  php artisan config:publish codesleeve/social

Usage

First you will need to configure the plugin. Let's walk through how to do it for facebook. You can see a complete list of other social sites below.

Next go edit the file at app/config/packages/codesleeve/social/config.php, here is a example for facebook,

  'facebook' => array(
  	'key' => '',
  	'secret' => '',
  	'scopes' => array('email'),
  	'redirect_url' => '/',
  ),

You will need to add at least a key and secret which can be obtained by creating a new facebok app

After the user logs in, if you want to redirect them somewhere besides the base path of your laravel application, then you can change the redirect_url.

Once you have configured facebook application open up a view and place

<a href="<?= Social::login('facebook') ?>">Login to facebook</a>

Now that you've connected with facebook, now you can access Facebook data about that user (provided you have requested that permission in your scopes array inside the package config)

You can pass api requests as a parameter to the Social::facebook facade, like so:

  $user = Social::facebook('/me');

You can see if a user is logged into a service like so

  if (Social::check('facebook')) {
    ...
  }

Another thing we've added is a common interface to get the logged in user by passing 'user' as the request.

  $user = Social::facebook('user');
  $user = Social::twitter('user');
  $user = Social::google('user');

This keeps us from having to deal directly with the api when we just simply want a user's info and nothing more.

Decoding json from apis

If you decide you want to decode your data differently from a provider you can set the decoder function. The example below shows how to decode into an associative array.

        Social::setDecoder(function($data) {
            return json_decode($data, true);
        });

Note though that this changes the decoder for all of the apis using Social, if you need to reset the decoder back you can do,

        Social::setDecoder(null);

Full example page

  <!doctype html>
  <html lang="en" class="login page">
  <head>
    <meta charset="8-UTF">
    <title>Login</title>
  </head>
  <body>
    <div class="container">
      <div class="login-social">
        <a href="<?= Social::login('facebook') ?>"><img src="http://ottopilotmedia.com/wp-content/uploads/2012/07/facebook-icon.jpg"></a>
      </div>
    </div>

    <pre>
      <?php if (Social::check('facebook')): ?>
        <?= print_r( Social::facebook('/120500222/feed') )?>
      <?php endif; ?>
    </pre>

  </body>
  </html>

Support

  • Facebook
  • Twitter
  • Google
  • GitHub

Please file an issue if you see a problem. And enjoy!

social's People

Contributors

kdocki avatar tabennett avatar nicksampsell avatar tantam avatar

Watchers

Rizwan R Syed avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.