PHP Classes

PHP StackExchange API : Access the StackExchange sites using its API

Recommend this page to a friend!

  Author Author  
Picture of Nahid Bin Azhar
Name: Nahid Bin Azhar <contact>
Classes: 23 packages by
Country: Bangladesh Bangladesh
Innovation award
Innovation award
Nominee: 6x

Winner: 2x


  Detailed description   Download Download .zip .tar.gz  
This package can access the StackExchange sites using its API.

It can send HTTP requests to the StackExchange API to perform several requests.

Currently, it can:

- Authenticate the current Web user

- Get the details of the current user accessing the API

- Find a user by a given ID

- Get the comments of a given user

- Get the available badges and the users that got a specific badge

Details

php-stack-api

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 :)

Requirements

  • CURL
  • PHP 5.5.9 +

Installation

To install this package with your project, just run this command in your terminal from project root.

composer require nahid/php-stack-api

Configurations

After installation complete successfully, you have to configure it correctly. This package is also Laravel compatible.

Laravel

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',
];

Pure PHP Project

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);

Usage

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.

Get Currently Authenticated Users Data

API URI: /me

For Laravel

$me = StackApi::me()->get();

Pure PHP

$stackApi = new StackApi($config);
$me = $stackApi->me()->get();

Users Information By User ID

API URI: /users/{ids}

For Laravel

$me = StackApi::users(1234)->get();

Pure PHP

$stackApi = new StackApi($config);
$me = $stackApi->users(1234)->get();

Here all of these data are Objects. So you can easily handle it.

The Easy Way

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();

Available Methods

  • `makeAuthUri()`
  • `getAccessToken()`
  • `info([$site[, $sort]])`
  • `me()`
  • `users($ids)`
  • `user($id)`
  • `get([$site[, $page[, $pageSize[, $sort[, $order[, $dateRange[, $minDate]]]]]]])`
  • `isExpired()`
  • `destroyAccessToken()`

For more about StackApps API you can read documentation

Thank you :)


  Classes of Nahid Bin Azhar  >  PHP StackExchange API  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: PHP StackExchange API
Base name: php-stack-api
Description: Access the StackExchange sites using its API
Version: -
PHP version: 5
License: MIT/X Consortium License
 
  Groups   Applications   Files Files  

  Groups  
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Web services Web data clipping, SOAP or XML-RPC clients and servers View top rated classes
Group folder image Social Networking Tools and components to integrate with social networking sites View top rated classes


  Innovation Award  
PHP Programming Innovation award nominee
February 2023
Nominee
Vote
StackExchange is a well-known network of sites where users can ask questions about how to solve problems specific to those communities.

One of those sites of the StackExchange network is StackOverflow. This is a site for programmers.

This package allows developers to access several aspects of sites of the StackExchange network using its API.

Manuel Lemos

  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Files folder imageconfig (1 file)
Files folder imagesrc (3 files, 2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  config  
File Role Description
  Accessible without login Plain text file stackapi.php Aux. Auxiliary script

  Files folder image Files  /  src  
File Role Description
Files folder imageFacades (1 file)
Files folder imagehelpers (1 file)
  Plain text file ConfigManager.php Class Class source
  Plain text file StackApi.php Class Class source
  Plain text file StackApiServiceProvider.php Class Class source

  Files folder image Files  /  src  /  Facades  
File Role Description
  Plain text file StackApi.php Class Class source

  Files folder image Files  /  src  /  helpers  
File Role Description
  Accessible without login Plain text file stackapis.php Lic. Auxiliary script

Download Download all files: php-stack-api.tar.gz php-stack-api.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
  Files folder image Files  
File Role Description
Files folder imageconfig (1 file)
Files folder imagesrc (3 files, 2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  config  
File Role Description
  Accessible without login Plain text file stackapi.php Aux. Auxiliary script

  Files folder image Files  /  src  
File Role Description
Files folder imageFacades (1 file)
Files folder imagehelpers (1 file)
  Plain text file ConfigManager.php Class Class source
  Plain text file StackApi.php Class Class source
  Plain text file StackApiServiceProvider.php Class Class source

  Files folder image Files  /  src  /  Facades  
File Role Description
  Plain text file StackApi.php Class Class source

  Files folder image Files  /  src  /  helpers  
File Role Description
  Accessible without login Plain text file stackapis.php Lic. Auxiliary script

Download Download all files: php-stack-api.tar.gz php-stack-api.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.