nahid/php-stack-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nahid/php-stack-api

Composer 安装命令:

composer require nahid/php-stack-api

包简介

Its a PHP SDK for StackExchange API version 2.2

README 文档

README

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

nahid/php-stack-api 适用场景与选型建议

nahid/php-stack-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.38k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2016 年 09 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「api」 「laravel」 「stackExchange」 「stackapi」 「stackapps」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nahid/php-stack-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nahid/php-stack-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 nahid/php-stack-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.38k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Creative
  • 更新时间: 2016-09-21