KLY Infeed - Google Manager v1
Requires
- guzzlehttp/guzzle: 6.3.3
Requires (Dev)
- phpunit/phpunit: 4.4.*
This package is auto-updated.
Last update: 2024-09-19 23:45:43 UTC
README
安装
要开始使用,请通过Composer包管理器安装Infeed Google AdManager:将Infeed Google AdManager添加到您的composer.json文件中。
require : {
"kly-infeed/gam": "2.0"
}
或者使用composer命令
composer require kly-infeed/gam
将提供者添加到您的app/config/app.php提供者
KLYinfeed\GAM\GamServiceProvider::class,
发布配置
php artisan vendor:publish
将别名添加到app/config/app.php别名
'GAM' => KLYinfeed\GAM\Facades\GAM::class,
配置
在开始使用Infeed Google AdManager之前,您还需要添加应用程序所使用的OAuth服务的凭据。这些凭据应放置在您的config/infeed_gam.php配置文件中,并应使用应用程序所需的提供者的client_id、client_secret和redirect。例如
return [
//auth
"client_id" => CLIENT_ID,
"client_secret" => 'CLIENT_SECRET',
"redirect" => 'http://your-site.com/callback',
"access_token" => null,
//cache
"cache_enabled" => false,
"cache_duration" => 3600, // Duration in minutes
"cache_key_prefix" => "KLYinfeed.GAM.",
"response_format" => "json", // json, xml
];
路由
接下来,您已准备好对应用程序进行认证!您需要两个路由:一个用于将用户重定向到OAuth提供者,另一个用于接收认证后Infeed Google AdManager的回调。我们将使用GAM外观访问Infeed Google AdManager。
<?php namespace App\Http\Controllers;
use GAM;
class TestController
{
/**
* Redirect the user to the Infeed Google AdManager authentication page.
*
* @return \Illuminate\Http\Response
*/
function auth()
{
return GAM::requestAccessToken([
'get-advertisers' //scope
]);
}
function callback()
{
$callback = GAM::callback();
dd($callback);
}
}
重定向方法负责将用户发送到OAuth提供者,而用户方法将读取传入的请求并从Infeed Google AdManager检索用户信息。
您需要定义路由到您的控制器方法
Route::get('auth', 'TestController@auth');
Route::get('callback', 'TestController@callback');
响应请求访问令牌
array:4 [▼
"token_type" => "Bearer"
"expires_in" => 1296000
"access_token" => ""
"refresh_token" => ""
]
当您获得访问令牌时,应将其保存到config/infeed_gam.php配置文件中,因为它避免了频繁请求令牌访问。默认情况下,访问令牌将每年过期,但在我们的系统中,令牌将自动刷新。
RESTful
Infeed API遵循更标准的REST约定,使用HTTP响应代码来标识响应的状态。这些包括但不限于
- 200 - 成功
- 400 - 无效
- 403 - 禁止
- 404 - 未找到
- 500 - 内部错误
GET请求将返回数据,POST请求用于创建,PATCH请求用于修改,DELETE请求用于删除。
获取用户
获取当前用户
GAM::me()
网络
获取当前网络
GAM::get('network', null, function($result){
dd($result);
});