![]() |
![]() ![]() |
![]() |
![]() ![]()
Post
#1
|
|
![]() Grupa: Zarejestrowani Postów: 211 Pomógł: 4 Dołączył: 29.10.2008 Ostrzeżenie: (0%) ![]() ![]() |
Witam,
Potrzebuję z poziomu PHP dostać się do dysku google i pobrać listę plików. Rzecz w tym że znalazłem przykład http://stackoverflow.com/questions/2186129...-issue/31947001 i kod z pytania działa, ale trzeba ręcznie się logować, a ja potrzebuje to zrobić z automatu. W drugim poście tego tematu ze stackoverflow, jest ponoć kod, który to umożliwia. Ponoć, bo mam problemy i nie wiem czy wszystko dobrze robię. Mój kod wygląda tak: CODE <?php require_once 'vendor/autoload.php'; require_once 'src/Google_Client.php'; require_once 'src/contrib/Google_DriveService.php'; require_once 'src/auth/Google_AssertionCredentials.php'; $client_email = 'xxxxxx@xxxxxxxxxxxxx.xxx.gserviceaccount.com'; $private_key = file_get_contents('key.p12'); $user_to_impersonate = 'xxxxxxxxxxxxxxx@gmail.com'; $scopes = array('https://www.googleapis.com/auth/drive'); $credentials = new Google_AssertionCredentials( $client_email, $scopes, $private_key, 'notasecret', // Default P12 password 'http://oauth.net/grant_type/jwt/1.0/bearer', // Default grant type $user_to_impersonate ); $client = new Google_Client(); $client->setAssertionCredentials($credentials); if ($client->getAuth()->isAccessTokenExpired()) { $client->getAuth()->refreshTokenWithAssertion(); } $service = new Google_Service_Drive($client); $files = $service->files->listFiles(); echo "count files=".count($files)."<br>"; foreach( $files as $item ) { echo "title=".$item['title']."<br>"; } ?> Katalog vendor uzyskałem z TEJ instrukcji, zaś resztę plików z Tąd Miałem problem z funkcją Google_Auth_AssertionCredentials, że nie może jej znaleźć, więc sam znalazłem, że jest plik src/auth/Google_AssertionCredentials.php ale z funkcją Google_AssertionCredentials, więc dołączyłem ten plik w kodzie i zmieniłem nazwę funkcji. Ostatecznie mam nowy błąd: Cytat PHP Fatal error: Cannot call constructor in \google_drive\vendor\google\apiclient-services\src\Google\Service\Drive.php on line 75 I nie wiem co mam dalej robić... Próbowałem masę różnych rzeczy, pobieranie listy plików przez sam adres url z API_KEY, przez jakieś pliki z jsonami. To do czego zmierzam, to pobieranie listy plików udostępnionych temu użytkownikowi, pobieranie, odczyt, edycja, zapis na dysku google. Jakieś sugestie? Pozdrawiam :-) Ten post edytował expert 9.10.2016, 19:19:14 |
|
|
![]() ![]() |
![]() |
Aktualny czas: 22.08.2025 - 02:51 |