镜像API权限不足,使用PHP插入帐户



我有PHP代码,谷歌PHP镜像API插入用户帐户。

    if(isset($_GET['userToken'])){
        $userToken=$_GET['userToken'];
        $key = file_get_contents($key_file_location);   
        $cred = new Google_Auth_AssertionCredentials(
            'service-email-here',
             array('https://www.googleapis.com/auth/glass', 'https://www.googleapis.com/auth/glass.thirdpartyauth'),
            $key
        );          
        $client->setAssertionCredentials($cred);
        $mirrorService = new Google_Service_Mirror($client);            
        $_SESSION['access_token'] = $client->getAccessToken();
        insert_account($mirrorService, $userToken, $email, $api_email);
        exit();
    }       

function insert_account($service,$userToken, $email, $api_email)
{
$accountType='package-name-here';
$accountName='service-email-here';
$authtoken=null;    
$postBody = new Google_Service_Mirror_Account();
$postBody->setAuthTokens($authtoken);
$userdata=array("email"=>$email);
$postBody->setUserData($userdata);
try {   
    $account = $service->accounts->insert($userToken, $accountType, $accountName, $postBody);
    return $account;
} catch (Exception $e) {
    echo "exception: ".$e;
    return null;
}
}

我得到一个错误说:

exception: exception 'Google_Service_Exception' with message 'Error calling POST      https://www.googleapis.com/mirror/v1/accounts/usertokenhere/package-name-here/service-email-here: (403) Insufficient Permission' in app-path/Google/Http/REST.php:79
Stack trace:
#0 app-path/Google/Http/REST.php(44): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request))
#1 app-path/Google/Client.php(508): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
#2 app-path/Google/Service/Resource.php(195): Google_Client->execute(Object(Google_Http_Request))
#3 app-path/Google/Service/Mirror.php(409): Google_Service_Resource->call('insert', Array, 'Google_Service_...')
#4 app-path/util.php(52): Google_Service_Mirror_Accounts_Resource->insert('8ce7d2ffbe6f693...', 'com.tenpearls.l...', '568533774877-an...', Object(Google_Service_Mirror_Account))
#5 app-path/add-your-own-camera.php(59): insert_account(Object(Google_Service_Mirror), '8ce7d2ffbe6f693...', 'safdar.tp@gmail...', '568533774877-an...')
#6 {main}

为什么我得到权限不足错误?我添加了范围https://www.googleapis.com/auth/glass.thirdpartyauth,这需要使用镜像api添加帐户。我需要使用镜像API插入用户帐户

您不需要范围https://www.googleapis.com/auth/glass。事实上,这根本不是一个有效的作用域。

使用业务帐户在设备上添加帐户所需的唯一作用域是https://www.googleapis.com/auth/glass.thirdpartyauth

调用插入帐户方法需要单独的服务客户端对象。代码可在此查看:http://goo.gl/DVggO6

最新更新