BitlyPHP
A simple PHP library for interacting with the Bit.ly API (including the new OAuth endpoints)
Install / Use
/learn @Falicon/BitlyPHPREADME
This is a very simple PHP library for interacting with the v3 bit.ly api (supports OAuth endpoints). It should support all basic endpoints that are found/available via http://dev.bitly.com/api.html.
============== REQUIREMENTS:
PHP, Curl, JSON
====== USAGE:
-
Simply download the bitly.php file and include it in your project directory
-
Make sure to include the file whenever you want to access the bitly api functionality... include_once('bitly.php');
-
Set up an associative array with the required parameters for the endpoint you want to access.
-
Make the bitly_get or bitly_post call, passing in the endpoint and the parameters as defined via the bit.ly API documentation ( http://dev.bitly.com/api.html ).
============= EXAMPLES:
include_once('bitly.php');
$params = array();
$params['access_token'] = 'THE_TOKEN_SET_VIA_OAUTH';
$params['longUrl'] = 'http://knowabout.it';
$params['domain'] = 'j.mp';
$results = bitly_get('shorten', $params);
var_dump($results);
$params = array();
$params['access_token'] = 'THE_TOKEN_SET_VIA_OAUTH';
$params['url'] = 'http://knowabout.it';
$results = bitly_get('link/lookup', $params);
var_dump($results);
a slightly more complex example with complex params (simply pass a third param of true when dealing with complex params):
$params = array();
$params['access_token'] = 'THE_TOKEN_SET_VIA_OAUTH';
$params['hash'] = array('dYhyia','dYhyia','abc123');
$results = bitly_get('expand', $params, true);
var_dump($results);
You can find more detailed examples in the test.php file within this repo.
============= SPECIAL NOTE:
To use the new OAuth endpoints, you must first obtain an access token for a user. You do this by passing the user off to bit.ly to approve your apps access to their account...and then you use the return code along with the bitly_oauth_access_token method to obtain the actual bitly access token:
- Present the user with a link as such:
https://bit.ly/oauth/authorize?client_id=YOUR_BITLY_CLIENT_ID&redirect_uri=THE_URL_YOU_WANT_BITLY_TO_REDIRECT_TO_WHEN_APP_IS_APPROVED_BY_USER
- a code ($_REQUEST['code']) will be supplied as a param to the url Bit.ly redirects to. So you can then execute:
$results = bitly_oauth_access_token($_REQUEST['code'],
'THE_URL_YOU_WANT_BITLY_TO_REDIRECT_TO_WHEN_APP_IS_APPROVED_BY_USER',
'YOUR_BITLY_APP_CLIENT_ID',
'YOUR_BITLY_APP_CLIENT_SECRET');
- If everything goes correctly, you should now have a $results['access_token'] value that you can use with the oauth requests for that user.
======= CONTACT:
As always, if you've got any questions, comments, or concerns about anything you find here, please feel free to drop me an email at info@falicon.com or find me on Twitter @falicon
======= License:
Copyright 2015 Kevin Marshall.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Related Skills
node-connect
351.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
110.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
351.2kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
351.2kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。