Giter Site home page Giter Site logo

bufferapp-php's Introduction

bufferapp-php

Simple PHP library for the amazing buffer at http://bufferapp.com

Why?

There wasn't one listed on Buffer's website and a quick Google search didn't turn one up. For most use cases Buffer's plugins will work just fine, but for those of you looking to pump lots of info into buffer via PHP this may help!

Using this library

  1. Include the file
    • Make sure you've got buffer.php included
  2. Create a new Buffer app
    • You'll need to register an app with buffer before you can begin
    • Initialize like this $buffer = new BufferApp($client_id, $client_secret, $callback_url); The callback_url needs to be the exact same as the app you registered
  3. Start adding buffers!
    • Once you're in you really only need to check $buffer->ok to see if you can perform actions, and then $buffer->go($endpoint, $data) to get going!
Image Attachments

The Buffer API seems to be missing documentation for the media parameter for creating an update.

Their example here includes media[link], media[title] & media[description].

To get the desired result you will need to use media[picture] and media[thumbnail].

Example

First thing's first: start a session and require buffer.php. We're going to be storing the access_token in the session for now.

	session_start();
	require('buffer.php');

Set this thing up with your credentials and your callback URL. Remember: callback_url must match what you've got in Buffer exactly!

	$client_id = '';
	$client_secret = '';
	$callback_url = 'http://127.0.0.1/callback';

Set up the new buffer client. This is a super simple action that does a few things under the hood. If $_GET['code'] is set on this page it assumes it came from Buffer and will attempt to trade that code for an access_token. If there is an access_token in the session it will be loaded in.

	$buffer = new BufferApp($client_id, $client_secret, $callback_url);

Once we've got an access_token set the $buffer->ok property will read true. It is false by default. Now that we've received access we are free to run queries against Buffer endpoints! Below we pull the list of profiles associated with the logged in buffer user and submit a test update to each one.

	if (!$buffer->ok) {
		echo '<a href="' . $buffer->get_login_url() . '">Connect to Buffer!</a>';
	} else {
		//this pulls all of the logged in user's profiles
		$profiles = $buffer->go('/profiles');
		
		if (is_array($profiles)) {
			foreach ($profiles as $profile) {
				//this creates a status on each one
				$buffer->go('/updates/create', array('text' => 'My first status update from bufferapp-php worked!', 'profile_ids[]' => $profile->id));
			}
		}
	}

Storage

Right now this baby just stores the access_token in $_SESSION['oauth']['buffer']['access_token']. If you are doing something serious with this you should probably rewrite the store_access_token() and retrieve_access_token() methods.

Realistically these methods should be replaced with some sort of abstraction -- pull requests are welcome!

License

Do whatever you like with this. Feel free (but not obligated) to drop me a line if it helps!

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.