Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not enough user ratings | Total: 23 | All time: 11,247 This week: 524 |
Version | License | PHP version | Categories | |||
php-stack-api 1.0 | MIT/X Consortium ... | 5 | PHP 5, Web services, Social Networking |
php-stack-api is a php SDK for StackExchange api version 2.2. Now you can easily access and hanlde all of StackApps Apis. Lets enjoy :)
To install this package with your project, just run this command in your terminal from project root.
composer require nahid/php-stack-api
After installation complete successfully, you have to configure it correctly. This package is also Laravel compatible.
Open config/app.php
and add this line end of the providers array
Nahid\StackApis\StackApiServiceProvider::class,
and then run this command in your terminal to publish config file
php artisan vendor: publish --provider="Nahid\StackApis\StackApiServiceProvider"
When you run this command stackapi.php
config file will be copy config
directory of your project. Now open app/stackapi.php
and file the credentials with your StackApps application.
return [
'client_id' => 1234,
'client_secret' => 'application-client-secret',
'key' => 'application-key-value',
'redirect_uri' => 'http://example.com/redirect-uri',
];
There are no special configuration for pure PHP project. You have to pass configuration data when the class is instantiated.
require 'vendor/autoload.php';
use Nahid\StackApis\StackApi;
$config = [
'client_id' => 1234,
'client_secret' => 'application-client-secret',
'key' => 'application-key-value',
'redirect_uri' => 'http://example.com/redirect-uri',
];
$stackApi = new StackApi($config);
Its has a lots of functionalities. When all of these are configured, you just use it like what you what.
At first you need to authenticate an user with your project. So make a authentication link.
<a href="<?= get_stack_api_auth_url(); ?>">Authenticate</a>
Its make a authentication url for StackExchange and get access_token
with your redirect_url. Now you are an authorized user and access all API from this package.
API URI: /me
$me = StackApi::me()->get();
$stackApi = new StackApi($config);
$me = $stackApi->me()->get();
API URI: /users/{ids}
$me = StackApi::users(1234)->get();
$stackApi = new StackApi($config);
$me = $stackApi->users(1234)->get();
Here all of these data are Objects. So you can easily handle it.
This package is well formatted as like as RestAPI URI. Really you amazed to see it.
For example, you want to get data where URI is /users/{ids}/comments
so the method will look like these
$data = StackApi::users($id)->comments()->get();
Or, if the URI is /users/{id}/network-activity
so the method will be
$data = StackApi::users($id)->networkActivity()->get();
> Note: 1. every URI you can call as PHP method chaining as per URI format. > 2. If you have a hyphen (-) separated URI, it will transform to camel case(camelCase) when you called as a method > 3. Every URI parameter goes to method parameter as per URI format.
Here the final example, if you have a URI like /badges/{ids}/recipients
$data = StackApi::badges($id)->recipients()->get();
For more about StackApps API you can read documentation
Thank you :)
Files (10) |
File | Role | Description | ||
---|---|---|---|---|
config (1 file) | ||||
src (3 files, 2 directories) | ||||
composer.json | Data | Auxiliary data | ||
composer.lock | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
README.md | Doc. | Documentation |
Files (10) | / | src |
File | Role | Description | ||
---|---|---|---|---|
Facades (1 file) | ||||
helpers (1 file) | ||||
ConfigManager.php | Class | Class source | ||
StackApi.php | Class | Class source | ||
StackApiServiceProvider.php | Class | Class source |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.