【问题标题】:Inserting account using Google Mirror API使用 Google Mirror API 插入帐户
【发布时间】:2014-10-22 18:24:22
【问题描述】:

编辑

我们已经通知谷歌这件事,他们解决了。现在错误消失了,但 $service->accounts->insert 现在只返回 null 而不是帐户。

我正在尝试通过 Google Mirror API 插入一个帐户。那我在做什么:

客户

$client = new Google_Client();
$client->setApplicationName($name);
$client->setClientId($client_id);
$client->setDeveloperKey($key);

服务

$service = new Google_Service_Mirror($client);

$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
    $service_account_name,
    [
        'https://www.googleapis.com/auth/glass.thirdpartyauth'
    ],
    $key
);
$client->setAssertionCredentials($cred);
if($client->getAuth()->isAccessTokenExpired()) {
  $client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client->getAccessToken();

// THIS IS NOT WORKING
$acc = insert_account($service, $user_token, $user_mail);

插入帐户

function insert_account($service, $userToken, $email) {

    $accountType = 'do.sli';

    $userDataArray= array();
    $userData1= new Google_Service_Mirror_UserData();
    $userData1->setKey('some');
    $userData1->setValue('data');
    $userDataArray[]=$userData1;

    $authTokenArray= array();
    $authToken1= new Google_Service_Mirror_AuthToken();
    $authToken1->setAuthToken('randomtoken');
    $authToken1->setType('randomType');
    $authTokenArray[]=$authToken1;

    $postBody = new Google_Service_Mirror_Account();
    $postBody->setUserData($userDataArray);
    $postBody->setAuthTokens($authTokenArray);
    $postBody->setFeatures(['access']);

    try {
        $account = $service->accounts->insert($userToken, $accountType, $email, $postBody);
    } catch (Exception $e) {
        var_dump($e->getMessage());
    }
    return $account;
}

var_dump 给我看这个

Error calling POST https://www.googleapis.com/mirror/v1/accounts/USER_TOKEN/ACCOUNT/EMAIL?key=DEVELOPERS_KEY: (400) Invalid Value

我不确定我做错了什么...我尝试了很多事情。不确定要检查什么。我正在尝试在我们的 Web 应用程序中验证来自 Glass Store 的用户并插入一个帐户,但是发生了这种情况。

谢谢!

【问题讨论】:

    标签: php google-glass google-mirror-api


    【解决方案1】:

    当您使用的 accountType 与在 MyGlass 后端中输入的不匹配时,通常会发生此错误:确保您让要使用的 accountType 的审核团队并仔细检查拼写错误.

    【讨论】:

    • 我们已经通知谷歌这件事,他们解决了。现在错误消失了,但是 `$service->accounts->insert` 现在只返回 null 而不是帐户。
    • null 响应主体的实际用途是:成功时,API 将使用201 No Content 响应代码进行响应。
    • 但文档说:If successful, this method returns an Accounts resource in the response body.。所以你基本上是说,null 响应是成功插入帐户?
    • 是的,如上所述,null 在这种情况下是成功响应。只需检查您是否有权访问设备上的帐户。
    【解决方案2】:

    我相当肯定,在您的应用被 Glassware“商店”接受之前,您无权访问此 API。

    见:https://developers.google.com/glass/develop/gdk/authentication

    【讨论】:

    • 但是,我已经接受了这个应用到 je store,它只适用于我们的 DEV,但它已经在商店里了,所以我可以访问
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-18
    • 2016-10-31
    • 1970-01-01
    • 2014-11-21
    • 2023-03-27
    • 1970-01-01
    相关资源
    最近更新 更多