标签: google-api-php-client

令牌必须是一个短期令牌并且在合理的时间范围内

我有相同的错误.就我而言,当应用尝试通过Google Cloud Client API上传文件时,就会发生这种情况.

POST https://www.googleapis.com/oauth2/v4/token
400 Bad Request
Invalid JWT: Token must be a short-lived token and in a reasonable timeframe
Run Code Online (Sandbox Code Playgroud)

我如何加载令牌是读取服务帐户json文件,并将其附加到CURLOPT_HTTPHEADERPHP中.它确实在过去一个月内正常运行,因此我猜测Google改变了授权方式.

谁有人面对并解决了这个问题?

php google-api google-api-php-client

48
推荐指数
4
解决办法
3万
查看次数

Google AnalyticsAPI - 获取特定网址的网页浏览信息

我希望在我的一个网站上实现页面查看跟踪系统.

该网站是供应商可以宣传其服务的目录.供应商在网站上有一个独特的个人资料页面,例如mysite.com/directory/abc-profile.html

这个想法是供应商可以登录他们在网站上的帐户区域,并查看有多少人访问他们的个人资料的统计数据.理想情况下,我想将其显示为:

Total views | Total today | This week | This month | This year

数据是否完全是最新的并不重要.

我已经在网站上安装了Google Analytics跟踪代码.是否可以使用Google AnalyticsAPI来检索此数据?如果是这样,我需要做什么样的查询?我查看了文档,但无法确定函数是否允许这样做.

我在服务器上使用PHP和MySQL.

google-analytics google-analytics-api google-api-php-client

44
推荐指数
3
解决办法
5万
查看次数

Youtube PHP APi检查VIdeo是否重复

您好我使用谷歌PHP API上传PHP视频.我已经按照本教程来实现它,它工作正常.但是如果我的频道中已经存在视频,则会出现问题,它也会返回视频详细信息,但我发现它无法复制.

所以我不能发现这是一个重复的视频,如果它是重复的,那么什么是主视频.表示主视频的视频详细信息,将其作为重复进行比较.

请帮我看一下这是一个重复的视频吗?

php youtube video youtube-api google-api-php-client

26
推荐指数
2
解决办法
2335
查看次数

从Google OAuth 2.0 PHP API获取Userinfo

我正在尝试使用Google Oauth API获取userinfo.它适用于Google Plus API,但我正在尝试创建备份,以防用户没有Google Plus帐户.验证过程是正确的,我甚至得到$ userinfo对象,但我究竟如何访问属性.我尝试了$ userinfo-> get()但它只返回用户的id.

难道我做错了什么?这是我正在使用的代码......

require_once '../../src/Google_Client.php';
require_once '../../src/contrib/Google_Oauth2Service.php';

session_start();

$client = new Google_Client();
$client->setApplicationName("Google+ PHP Starter Application");
// Visit https://code.google.com/apis/console to generate your
// oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.
 $client->setClientId('*********************');
 $client->setClientSecret('**************');
 $client->setRedirectUri('***************');
 $client->setDeveloperKey('**************');
$plus = new Google_Oauth2Service($client);

if (isset($_REQUEST['logout'])) {
  unset($_SESSION['access_token']);
}

if (isset($_GET['code'])) {
  $client->authenticate($_GET['code']);
  $_SESSION['access_token'] = $client->getAccessToken();
  header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
}

if (isset($_SESSION['access_token'])) {
  $client->setAccessToken($_SESSION['access_token']);
}

if ($client->getAccessToken()) 
{
    $userinfo = $plus->userinfo;
    print_r($userinfo->get());

} else 
{
    $authUrl …
Run Code Online (Sandbox Code Playgroud)

php google-api oauth-2.0 google-api-php-client

25
推荐指数
2
解决办法
3万
查看次数

Gmail API返回403错误代码和"<用户电子邮件>拒绝委托"

检索包含此错误的邮件时,某个域的Gmail API失败:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 OK
{
  "code" : 403,
  "errors" : [ {
    "domain" : "global",
    "message" : "Delegation denied for <user email>",
    "reason" : "forbidden"
  } ],
  "message" : "Delegation denied for <user email>"
}
Run Code Online (Sandbox Code Playgroud)

我正在使用OAuth 2.0和Google Apps域范围的授权来访问用户数据.域已授予应用程序的数据访问权限.

oauth-2.0 google-oauth google-api-php-client gmail-api

24
推荐指数
1
解决办法
2万
查看次数

使用Youtube API V3和PHP将视频上传到Youtube

我正在尝试使用PHP将视频上传到Youtube.我正在使用Youtube API v3,我正在使用最新检出的Google API PHP客户端库源代码.
我使用
https://code.google.com/p/google-api-php-client/上提供的示例代码来执行身份验证.身份验证很顺利,但是当我尝试上传视频时,我得到Google_ServiceException的错误代码为500,消息为null.

我看了之前提到的以下问题: 使用php客户端库v3视频上传到youtube但是接受的答案没有描述如何指定要上传的文件数据.
我发现了另一个类似的问题使用Youtube API v3和PHP上传文件,其中在评论中提到categoryId是必需的,因此我尝试在片段中设置categoryId,但它仍然提供相同的异常.

我还提到了文档站点上的Python代码(https://developers.google.com/youtube/v3/docs/videos/insert),但我在客户端库中找不到函数next_chunk.但我试图在循环(在代码片段中提到)重试获取错误代码500,但在所有10次迭代中我得到相同的错误.

以下是我正在尝试的代码段:

$youTubeService = new Google_YoutubeService($client);
if ($client->getAccessToken()) {
    print "Successfully authenticated";
    $snippet = new Google_VideoSnippet();
    $snippet->setTitle = "My Demo title";
    $snippet->setDescription = "My Demo descrition";
    $snippet->setTags = array("tag1","tag2");
    $snippet->setCategoryId(23); // this was added later after refering to another question on stackoverflow

    $status = new Google_VideoStatus();
    $status->privacyStatus = "private";

    $video = new Google_Video();
    $video->setSnippet($snippet);
    $video->setStatus($status);

    $data = file_get_contents("video.mp4"); …
Run Code Online (Sandbox Code Playgroud)

php youtube-api google-api-php-client

21
推荐指数
1
解决办法
4万
查看次数

Google Calendar API v3 - 使用硬编码凭据进行身份验证

我正在编写一个PHP应用程序,它应该允许用户将某些事件添加到私人Google日历中.日历由我拥有,我需要一种方法让PHP使用固定凭据与日历API进行通信(每个人都可以使用网站上的表单添加事件,但日历本身不公开).

根据我的阅读,可以在v1 API中使用ClientLogin.但是,在v3 API中,可用选项是OAuth2.0或API密钥.使用API​​密钥似乎不起作用,因为它只能用于不需要授权的请求,而OAuth似乎也不正确,因为用户不应该访问他们自己的日历,而是我的日历应用程序使用

我考虑以编程方式获取OAuth令牌,但由于OAuth对话框可以使用验证码,因此迟早会中断.

这似乎是一个标准的用例 - 一个允许用户以某种预定义的方式与单个日历交互的Web应用程序 - 但我找不到任何关于如何在v3 API中实现它的文档.谁能帮我?

php google-calendar-api google-api google-api-php-client google-oauth2

19
推荐指数
2
解决办法
2万
查看次数

如何在PHP中访问Google Spreadsheets API?

Google Spreadsheets API上的Google Developer 文档开始,我发现"许多客户端库都以各种语言提供.",但Google仅提供Java和.NET的客户端库.对于PHP库,他们建议使用Zend GData.因此,我领导了Zend GData回购,Zend表示他们的GData组件已停产,并使用Google API Client Library for PHP.该库不适用于Spreadsheets API,因为您必须返回到我开始使用的原始页面.

所以,似乎每个人都在推卸责任.我只需要编写一些PHP代码来请求和处理来自Google电子表格的数据.我怎么做?请不要将我链接到类似的帖子或页面而不检查以确保它们是100%最新的,我一直在筛选大量的帖子几个小时,这些帖子都是过时的和已弃用的依赖项.

php google-api google-api-php-client google-sheets-api

19
推荐指数
2
解决办法
2万
查看次数

Google Drive PHP API - 简单文件上传

我正在尝试编写一个小脚本,使用Google Drive PHP API将本地文件上传到Google云端硬盘.文档维护得很差,但到目前为止,我很确定代码应该是这样的:

<?php

include_once 'Google/Client.php';
include_once 'Google/Service/Drive.php';
include_once 'Google/Auth/OAuth2.php';

$client = new Google_Client();

$client->setScopes(array('https://www.googleapis.com/auth/drive.file'));
$client->setClientId('dfgdfgdg');
$client->setClientSecret('dfgdfgdf');
$client->setRedirectUri('urn:ietf:wg:oauth:2.0:oob');


$service = new Google_Service_Drive($client);

$data = file_get_contents("a.jpg");

// create and upload a new Google Drive file, including the data
try
{
//Insert a file
$file = new Google_Service_Drive_DriveFile($client);

$file->setTitle(uniqid().'.jpg');
$file->setMimeType('image/jpeg');

$createdFile = $service->files->insert($file, array(
    'data' => $data,
    'mimeType' => 'image/jpeg',
    'uploadType' => 'media',
));
}
catch (Exception $e)
{
    print $e->getMessage();
}

print_r($createdFile);

?>
Run Code Online (Sandbox Code Playgroud)

问题是我无法正确进行身份验证(或者我正在做其他错误的事情?).我收到的错误是:

HTTP Error: Unable to connect: 'fopen(compress.zlib://https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart) …
Run Code Online (Sandbox Code Playgroud)

php google-drive-api google-api-php-client

18
推荐指数
1
解决办法
6万
查看次数

Google日历推送通知设置

我正在尝试使用PHP和V3 api为Google日历设置推送通知.

我获得了Auth2.0权限,并且能够从我的应用程序在谷歌上创建事件.现在我想知道用户何时在谷歌日历上进行任何更改(CRUD操作).

这是我的代码:

private $imageService;
public $google_client;
public $google_calendar;

public function __construct()
{
    $this->imageService = new ImageService();
    $this->google_client = new Google_Client();
    $this->google_client->setApplicationName($_ENV['GOOGLE_APP_NAME']);
    $this->google_client->setDeveloperKey($_ENV['GOOGLE_API_KEY']);
    $this->google_client->setClientId($_ENV['CLIENT_ID']);
    $this->google_client->setClientSecret($_ENV['CLIENT_SECRET']);
    $this->google_client->setAccessType('offline');
    $this->google_client->setIncludeGrantedScopes(true);
    $this->google_client->setScopes(array('email', 'profile', 'https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/calendar'));
    $this->google_calendar = new Google_Service_Calendar($this->google_client);

}

 public function googleCalendarWatch($uuid){

    $channel =  new Google_Service_Calendar_Channel($this->google_client);
    $channel->setId($uuid);
    $channel->setType('web_hook');
    $channel->setAddress("https://example.com/google/googleNotifications");
    $channel->setExpiration("1919995862000");
    $this->google_calendar->events->watch('primary', $channel);

}
Run Code Online (Sandbox Code Playgroud)

这个输出如下:

Google_Service_Calendar_Channel Object (
    [internal_gapi_mappings:protected] => Array ( ) 
    [address] => 
    [expiration] => 1426272395000 
    [id] => aee2b430-34bf-42bc-a597-ada46db42799 
    [kind] => api#channel 
    [params] => 
    [payload] => 
    [resourceId] => 51IKGpOwCJ6EMraQMUc1_04MODk 
    [resourceUri] => …
Run Code Online (Sandbox Code Playgroud)

php calendar google-calendar-api google-api-php-client

17
推荐指数
1
解决办法
1117
查看次数