标签: google-api-php-client

PHP Google API Client v3获取联系人

我仍然遇到新的google_api_client php库的问题.我正在尝试检索用户的联系人.

我非常接近正确的解决方案......我的意思是,我得到了所有结果,但是无法解析它.

可能是因为我对XML解析器不够强大.经过测试和测试......我得到了这个解决方案(基于Google的示例文件):

...
$req = new apiHttpRequest("https://www.google.com/m8/feeds/contacts/default/full");         
$val = $client->getIo()->authenticatedRequest($req);
$response = simplexml_load_string($val->getResponseBody());

foreach($response->entry as $entry)
{
    $child = $entry->children("http://schemas.google.com/g/2005");
    $mail_info = $child->attributes();
}
...
Run Code Online (Sandbox Code Playgroud)

在$ response中,我可以获得存储联系人姓名的title字段,在$ mail_info中有一个对象,当我收到电子邮件地址时,我会看到地址字段.

这是SAD和UGLY解决方案......如果我想要公司名称,地址......电话号码......照片怎么办?所有这些信息在哪里?

如何在一个优秀而干净的解决方案中使用Google响应?

任何人都可以给我一些帮助.再见

php google-api xml-parsing google-api-php-client

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

Google API:使用OAuth验证请求但未经用户同意窗口,然后请求Google数据以获取特定用户名或用户ID

在阅读此实施OAuth 2.0身份验证(服务器端)时,我注意到该流程可能适用于创建应用程序的情况,该应用程序允许用户使用其Google凭据登录并随后显示其Google+帖子,Youtube视频等.

我需要的是能够根据谷歌用户的用户名或用户ID获取谷歌数据.我确实有来自Google的client_id,client_secret等 - 而且我愿意按照我的要求发送它们.

第1步似乎没问题.提出类似这样的请求:

https://accounts.google.com/o/oauth2/auth?
client_id=1084945748469-eg34imk572gdhu83gj5p0an9fut6urp5.apps.googleusercontent.com&
redirect_uri=http%3A%2F%2Flocalhost%2Foauth2callback&
scope=https://www.googleapis.com/auth/youtube&
response_type=code&
access_type=offline
Run Code Online (Sandbox Code Playgroud)

在这一步之后可能会有什么好处,只需要获取代码,以便我可以验证我的请求(通过Google_Client() - > authenticate($ _ GET ['code']);或类似的),然后将其交换为auth_token.

我使用Facebook API for PHP获得类似于获取Facebook个人资料/页面公共帖子的内容 - 因此与FB流程的登录不同 - 不需要用户同意也不需要用户同意.

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

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

使用gmail-api和google-api-php-client发送电子邮件

我正在使用https://github.com/google/google-api-php-client,我想发送一封包含用户授权的Gmail帐户的测试电子邮件.

这是我到目前为止:

$msg = new Google_Service_Gmail_Message();  
$msg->setRaw('gp1');  
$service->users_messages->send('me', $msg);  
Run Code Online (Sandbox Code Playgroud)

这导致退回电子邮件,因为我不知道如何设置原始邮件.我在经过身份验证的用户的收件箱中看到了反弹.我想学习如何设置电子邮件的"收件人","抄送","密件抄送","主题"和"正文"的值.我相信我还需要对原始数据进行64位编码.我可能想在我的电子邮件正文中使用一些HTML.

请帮助提供使用gmail-api和google-api-php-client发送电子邮件的工作示例.

以下是收件箱中的退回电子邮件:

Bounce -nobody@gmail.com- 12:58 PM(7分钟前)
给我
发生错误.您的邮件未发送.

,日期:星期四,2014年7月24日10:58:30 -0700消息ID:CABbXiyXhRBzzuaY82i9iODEiwxEJWO1 = jCcDM_TH-

google-api-php-client gmail-api

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

Google_Service_Drive retrieveListOfAllFiles仅返回一个文件

当我从php运行API时,返回的唯一项目是"如何开始使用Drive"文件,该文件不在文件夹中,但是当我从API网页运行retrieveListOfAllFiles()时,我看到驱动器中的所有文件.这是代码.

set_include_path(ABSPATH . "path-to/api/google-api-php-client/src/");
require_once "Google/Client.php";
require_once "Google/Service/Drive.php";
require_once "Google/Auth/OAuth2.php";
require_once "Google/Auth/AssertionCredentials.php";

  define('CLIENT_ID', 'xxxxx');
  define('SERVICE_ACCOUNT_NAME', 'xxxxx');
  $key    = file_get_contents(ABSPATH . "path-to-.p12");
  $scopes = array('https://www.googleapis.com/auth/drive.readonly');


  $client = new Google_Client();
  $client->setApplicationName("xxxx");

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

  $auth = new Google_Auth_AssertionCredentials(
    SERVICE_ACCOUNT_NAME,
    $scopes,
    $key
  );

  $client->setAssertionCredentials($auth);

  if ($client->getAuth()->isAccessTokenExpired()) {
    $client->getAuth()->refreshTokenWithAssertion($auth);
  }

  $_SESSION['service_token'] = $client->getAccessToken();

  $service = new Google_Service_Drive($client);

  $files = retrieveAllFiles($service);
Run Code Online (Sandbox Code Playgroud)

文件仅返回"如何开始使用驱动器"文件 - 从此页面进行API测试:https://developers.google.com/drive/v2/reference/files/list返回驱动器中的所有文件.

ID正确,.p12文件是新的和加载,我不知道出了什么问题.

我也注意到,如果我var_dump()的输出

dump($service->files->listFiles(array()));
Run Code Online (Sandbox Code Playgroud)

我也只获得单曲"如何开始使用驱动器"文件.所以,即使我没有收到任何OAuth2错误,并获得密钥令牌等,我想要列出文件的驱动器也没有被访问.

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

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

如何在Google云端存储中重命名或移动文件(PHP API)

我目前正在尝试将云存储文件重命名和/或移动到另一个名称/位置,但我无法让它工作.我使用https://github.com/google/google-api-php-client作为客户端,上传工作正常:

...
$storageService = new \Google_Service_Storage( $client )
$file = new \Google_Service_Storage_StorageObject()
$file->setName( 'test.txt' );
$storageService->objects->insert(
   $bucketName,
    $file,
    array(
        'name'          => $filename,
        'data'          => file_get_contents( $somefile )
    )
);
...
Run Code Online (Sandbox Code Playgroud)

所以我试图通过$ storageObject-> objects-> update()方法更改文件名,但我找不到任何关于此的文档.我使用$ storageService-> objects-> get($ bucketName,$ fileName)来获取我想要重命名的特定文件(使用$ file-> setName()),但似乎我无法将文件传递给对象 - >更新功能.我做错了吗?

php google-app-engine google-cloud-storage google-api-php-client

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

通过"google-api-php-client"库检索Google搜索分析

我仍然是任何API的初学者,所以需要帮助.据我了解,服务"网站管理员"谷歌的API的PHP客户端库允许我收到这样的数据CTR,Clicks等等.

我从github下载了lib文件并将其打入localhost.然后在谷歌开发者控制台中我创建了项目(真的不明白,为什么?这个项目不包含任何关于网站的信息,我需要哪些搜索信息).而对于项目创建服务器密钥后(通过"添加凭据"谷歌开发者控制台,而无需输入任何IP它).Google Search Console API已启用.我是我网站的完全用户(我可以在Google Search Console中看到它).我也有谷歌帐户,当然,并登录.

我在lib的examples文件夹中创建的源文件,以及其他示例:

include_once "templates/base.php";    
require_once realpath(dirname(__FILE__) . '/../src/Google/autoload.php');

$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
$apiKey = "AIzaSyCOJ56353XByxh8rCpfgfhgfhZzopSLUe"; // Value of server key, that I created in for my project ().

if (strpos($apiKey, "<") !== false) {
  echo missingApiKeyWarning();
  exit;
}
$client->setDeveloperKey($apiKey);

//here are my efforts
$service = new Google_Service_Webmasters($client);
var_dump($service->searchanalytics->query(
'http://sschesnok.com.ua',
 new Google_Service_Webmasters_SearchAnalyticsQueryRequest())); //I'm not sure about …
Run Code Online (Sandbox Code Playgroud)

php api google-webmaster-tools google-api-php-client

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

Google API - 来自Oauth2的令牌请求返回null令牌

对于凭据,我在https://console.developers.google.com上创建了一个开发人员帐户,我创建了一个项目,然后我从API Manager创建了凭据.我使用"google/apiclient":"1.1.*"包.我认为这是凭证的问题.

    $OAUTH2_CLIENT_ID = 'XXXXX-rvm1l9b1nvht9je1ic0bbe05ab5gvhbg.apps.googleusercontent.com';
    $OAUTH2_CLIENT_SECRET = 'XXXXXXP90L_DLD3Nrc_rT4zGD';

    $client = new Google_Client();
    $client->setClientId($OAUTH2_CLIENT_ID);
    $client->setClientSecret($OAUTH2_CLIENT_SECRET);
    $client->setScopes('https://www.googleapis.com/auth/youtube');
    $redirect = url('/');
    $client->setRedirectUri($redirect);


    $token = $client->getAccessToken();
    dd($token);
Run Code Online (Sandbox Code Playgroud)

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

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

带有PHP服务帐户的Google OAuth 2.0:"无效的令牌格式错误"

我创建了我的服务帐户,获得了private_key并委托了域范围的权限.

这是我的代码尝试使用服务帐户进行身份验证,但获得相同的"无效的令牌格式错误":

session_start();
include_once 'google-api-php/vendor/autoload.php';

function getClient() {
$client = new Google_Client();
$client->setApplicationName('theName');
$client->setScopes('https://www.googleapis.com/auth/admin.directory.user.readonly');
$client->setAccessType('offline');
$client->setSubject('admin@domain.com');
$client->setAuthConfig('private_key.json');

// Load previously authorized credentials from a file.
$credentialsPath = 'private_key.json';
if (file_exists($credentialsPath)) {
    $accessToken = json_decode(file_get_contents($credentialsPath), true);
}
else {
    // Request authorization from the user.
    $authUrl = $client->createAuthUrl();
    printf("Open the following link in your browser:\n%s\n", $authUrl);
    print 'Enter verification code: ';
    $authCode = trim(fgets(STDIN));

    // Exchange authorization code for an access token.
    $accessToken = $client->fetchAccessTokenWithAuthCode($authCode);

    // Store the credentials to disk. …
Run Code Online (Sandbox Code Playgroud)

php oauth-2.0 google-api-php-client service-accounts google-admin-sdk

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

Google API:如何增加访问令牌的到期日期?

Google API 到期日期是 1 小时,问题是我使用 API 是为了允许用户使用管理 SDK 功能(列出群组、将成员添加到群组等)

没有人可以在一小时内完成任何一项工作,这将要求用户每天多次登录他们的帐户来管理他们的群组。如果您只想使用 Google 对用户进行身份验证,那么 1 小时的到期日期是不错的选择。

如何增加它或有任何解决方法?我错过了什么吗?

google-api google-api-php-client google-admin-sdk google-php-sdk google-workspace

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

"PHP致命错误:在Google Drive php UPDATE脚本中调用非对象上的成员函数setTitle()

我正在使用这个PHP脚本将文件INSERT(上传)到我的Google云端硬盘,它的完美:

require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';

$drive = new Google_Client();

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

$gdrive = new Google_DriveService($drive);

$drive->setAccessToken(file_get_contents('token.json'));

$doc = new Google_DriveFile();

$doc->setTitle('Test');
$doc->setDescription('Test Document');
$doc->setMimeType('text/plain');

$content = file_get_contents('test.txt');

$output = $gdrive->files->insert($doc, array(
      'data' => $content,
      'mimeType' => 'text/plain',
    ));

print_r($output);
Run Code Online (Sandbox Code Playgroud)

现在我想更新(不上传)我现有的Google云端硬盘文件,我正在使用此脚本:

require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';

$drive = new Google_Client();

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

$gdrive = new Google_DriveService($drive);

$drive->setAccessToken(file_get_contents('token.json'));

$fileId = "ZZZ";
$doc = $gdrive->files->get($fileId);

$doc->setTitle('Test'); // HERE I GET THE ERROR "CALL TO A MEMBER …
Run Code Online (Sandbox Code Playgroud)

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

0
推荐指数
1
解决办法
2384
查看次数

CakePHP 3 - 使用Google API客户端

我已经通过composer安装了Google PHP API客户端库; https://github.com/google/google-api-php-client

guzzle,psr,monolog,firebase和google目录现已在我的供应商目录中创建.

但是,我很难将其添加为我的控制器中的依赖项.

大多数答案表明你需要创建一个Cake插件才能在核心中使用新的库,但我很难找到解释如何执行此操作的任何资源.

在不属于蛋糕核心的控制器中使用新库的正确方法是什么?

php cakephp google-api google-api-php-client cakephp-3.0

0
推荐指数
1
解决办法
2651
查看次数

为PHP设置YouTube API v3

我想将YouTube API版本3用于php。我从GitHub下载php的示例。

在Google控制台的YouTube API上,替换DEVLOPER_KEY样本文件。然后我看到每个文件中都有两个文件include Google/Client.phpGoogle/Service/YouTube.php

这两个文件不在我下载的示例文件夹中,因此,我在google上搜索并为php下载google客户端库。然后我运行示例文件,它显示错误。

致命错误:在第32行上 Google_Service找不到类D:\wamp\www\api\php\Google\Service\YouTube.php

问题是什么,我错过任何事情都不能正确下载所有内容?请指导我。谢谢。

php google-api-php-client youtube-data-api

-1
推荐指数
1
解决办法
1630
查看次数