【问题标题】:How to a users Google+ cover programticly如何以编程方式覆盖用户 Google+
【发布时间】:2016-04-05 11:14:48
【问题描述】:

我在使用 php(zend 框架)和 Oauth 更新用户封面图片时遇到问题。

我在 composer.json 中添加了以下几行:

"require" : {
"google/auth": "0.7",
"google/apiclient" : "^2.0.0@RC"
}

之后,我使用和 oppp 制作了 composer-install + composer-update,我得到了我的供应商内部的库。

我已经按照谷歌官方教程在谷歌开发控制台中配置了我的应用程序:D

现在在我的控制器中,我可以使用这种方法轻松地请求谷歌网络服务:

public function googleplusAction()
{
    Zend_Loader::loadFile("HttpPost.class.php");
    $client_id = "id_here";
    $client_secret = "secret_here";
    $application_name = "application_name_here";
    $redirect_uri = "redirection_uri_here";

    $oauth2_server_url = 'https://accounts.google.com/o/oauth2/auth';

    $query_params = array(
        'response_type' => 'code',
        // The app needs to use Google API in the background
        'client_id' => $client_id,
        'redirect_uri' => $redirect_uri,
        'scope' => 'https://www.googleapis.com/auth/userinfo.profile'
    );

    $forward_url = $oauth2_server_url . '?' . http_build_query($query_params);
    header('Location: ' . $forward_url);
}

之后,我被重定向到我的重定向 URI,并在栏地址中获得一个新变量“代码”。

直到现在,我希望一切都好,来到最重要的部分,重定向 URI 页面的控制器,使用我在尝试获取访问令牌之前讨论过的“代码”变量,但我失败了。

这是应该在google plus上设置新封面图片的方法:

$client_id = "client-id";
    $client_secret = "g+-secret";
    $application_name = "my-app-name";
    $redirect_uri = "my-uri-on-g+";

    $client = new Google_Client();
    $client->setClientId($client_id);
    $client->setClientSecret($client_secret);
    $client->setRedirectUri($redirect_uri);
    $service = new Google_Service_Oauth2($client);
    $client->addScope(Google_Service_Oauth2::USERINFO_PROFILE);
    $client->authenticate($_GET['code']); // I have the right code, and I am being authenticated
    $plus = new Google_Service_Plus($client);
    $person = $plus->people->get('me');
    var_dump($person);
    $pic = $this->session->image['generatedAbs'];
    $gimg = new Google_Service_Plus_PersonCover();
    $source = new Google_Service_Plus_PersonCoverCoverPhoto();
    $source ->setUrl("$photo-that-i-wanted-to-put-on-g+");
    $gimg->setCoverPhoto($source);

    $person->setCover($gimg);}

所以我的问题是:

  1. 如何将我的 google plus 封面图片更改为项目中已有的新 png 或 JPEG 图片?

在 G+ 库中我找到了这个方法:

Google_Service_Plus_PersonCoverCoverPhoto();

在一个名为

的类中
Google_Service_Plus_PersonCover(); 

但是我该如何使用它呢?

【问题讨论】:

    标签: php zend-framework google-api google-plus


    【解决方案1】:

    我认为客户端库使用方法Google_Service_Plus_PersonCoverCoverPhoto()Google_Service_Plus_PersonCover()在检索信息时对其进行设置。这并不意味着您能够更新 Google+ 上的用户封面,如果确实有效,它只会更新真正没有意义的类对象(IMO)。

    var_dump($person->Cover);
    

    如果您查看Plus.People 文档,您会发现没有更新或修补方法。这是因为目前无法以编程方式更新用户信息。

    回答:您无法更新用户封面图片与 Oauth 无关,这与 API 不允许这样做有关。不幸的是,您似乎白白做了很多工作,这就是为什么在开始之前始终查阅文档是一件好事,您会发现这是不可能的,并且可以避免给自己带来很多不必要的压力。

    【讨论】:

    • 好吧,有什么办法至少可以将该图片添加到用户相册中?
    • 查看 Picasa api 或我不熟悉这些 api 的新 Google 照片
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-25
    • 2015-05-18
    • 2010-12-07
    • 2021-05-10
    • 2014-12-10
    • 1970-01-01
    • 2017-06-22
    相关资源
    最近更新 更多