2016-11-24 117 views
0

我在使用Google雲端存儲和Google Play報告時遇到問題。我想在PHP中解析我的服務器上的報告。爲此,我想將默認應用程序存儲區中的文件移至新的應用程序存儲區。當我嘗試這樣做時,出現以下錯誤:將商店報告複製到個人Google雲端存儲桶

Fatal error: Uncaught exception 'Google_Service_Exception' with message '{ "error": { "errors": [ { "domain": "global", "reason": "notFound", "message": "Not Found" } ], "code": 404, "message": "Not Found" } } ' in /var/www/d2/libs/googleAPI/src/Google/Http/REST.php:118 Stack trace: #0 /var/www/d2/libs/googleAPI/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1 [internal function]: Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 /var/www/d2/libs/googleAPI/src/Google/Task/Runner.php(181): call_user_func_array(Array, Array) #3 /var/www/d2/libs/googleAPI/src/Google/Http/REST.php(58): Google_Task_Runner->run() #4 /var/www/d2/libs/googleAPI/src/Google/Client.php(781): Google_Http_REST::execute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...', Array) #5 /var/www/d2/libs/googleAPI/src/Google/Service in /var/www/d2/libs/googleAPI/src/Google/Http/REST.php on line 118 

我不知道爲什麼,因爲目標存儲區存在原始文件。

這是我實現我的PHP腳本:

<?php 

session_start(); 

require_once dirname(__FILE__).'/../libs/googleAPI/vendor/autoload.php'; 

$scopes = array("https://www.googleapis.com/auth/cloud-platform"); 

// Create client object 
$client = new Google_Client(); 
$client->setRedirectUri('http://CENSORED/TEST_API.php'); 
$client->setAuthConfig("client_credentials_OAUTH.json"); 
$client->addScope($scopes); 

if (isset($_SESSION['access_token']) && $_SESSION['access_token']) 
{ 
    $client->setAccessToken($_SESSION['access_token']); 
    $service = new Google_Service_Storage($client); 
    $request = $service->objects->listObjects("statsinstalls"); 
    $objects = $request->getItems(); 

    $sourceBucket = "pubsite_prod_rev_CENSORED"; 
    $sourceObject = "installs_CENSORED_" . date("Ym") . "_app_version.csv"; 
    $destinationBucket = "statsinstalls"; 
    $destinationObject = $sourceObject; 

    $postBody = new Google_Service_Storage_StorageObject($client); 

    $response = $service->objects->copy($sourceBucket, $sourceObject, $destinationBucket, $destinationObject, $postBody);    

    foreach ($objects as $item) 
     echo $item->id . "<br>"; 
} 
else if (!isset($_GET['code'])) 
{ 
    $auth_url = $client->createAuthUrl(); 
    header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL)); 
} 
else 
{ 
    $client->authenticate($_GET['code']); 
    $_SESSION['access_token'] = $client->getAccessToken(); 
    $redirect_uri = 'http://CENSORED/TEST_API.php'; 
    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL)); 
} 

爲什麼我得到一個404錯誤? 謝謝。

回答

1

我找到了解決方案。源對象必須是文件的完整路徑。

我只是代替:

$sourceObject = "installs_CENSORED_" . date("Ym") . "_app_version.csv"; 

由:

$sourceObject = "stats/installs/installs_CENSORED_" . date("Ym") . "_app_version.csv"; 

和工作做好了。現在我將嘗試將此CSV轉換爲PHP數組

相關問題