Hier ist mein Code,konnte nicht json dekodieren das Token
<?php
session_start();
$url = 'http://localhost:8080/google-drive/index.php?msg=Successfully Uploaded!';
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
$client = new Google_Client();
if(isset($_POST['submit'])){
$files = glob('files/*'); // get all file names
foreach($files as $file){ // iterate files
if(is_file($file))
unlink($file); // delete file
}
$uploaddir = 'files/';
$uploadfile = $uploaddir . basename($_FILES['fileToUpload']['name']);
move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $uploadfile);
}
$files= array();
$dir = dir('files');
while ($file = $dir->read()) {
if ($file != '.' && $file != '..') {
$files[] = $file;
}
}
$dir->close();
if (!empty($_POST)) {
$token = file_get_contents('auth.txt');
echo $token;
$token = array(
'access_token' => 'xxxxxx',
'token_type' =>'Bearer',
'expires_in' =>'3600',
'refresh_token' => 'xxxxx',
'created' => 'xxxxxxx'
);
$tokennew = json_encode($token);
$client->setClientId('xxxxxxxxxx');
$client->setClientSecret('xxxxxx');
$client->setAccessType('offline');
$client->setScopes(array('https://www.googleapis.com/auth/drive'));
$client->setAccessToken($tokennew);
$service = new Google_DriveService($client);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$file = new Google_DriveFile();
foreach ($files as $file_name) {
$file_path = 'files/'.$file_name;
$mime_type = finfo_file($finfo, $file_path);
$file->setTitle($file_name);
$file->setDescription('This is a '.$mime_type.' document');
$file->setMimeType($mime_type);
$service->files->insert(
$file,
array(
'data' => file_get_contents($file_path),
'mimeType' => $mime_type
)
);
}
finfo_close($finfo);
header('location:'.$url);
exit;
}
include 'app.php';
?>
, wenn ich diese Datei ausgeführt I ‚mit der Meldung‚‚abgefangene Ausnahme‘ Google_AuthException bekam konnte nicht json dekodieren das Token‘. Ich möchte Zugriffstoken aus der Textdatei lesen und an die Funktion setAccessToken() übergeben. Access Token druckt gut. Wo irre ich mich?
Mögliches Duplikat http://stackoverflow.com/questions/23886132/uncaught-exception-google-auth-exception-with-message-could-not-json- dekodieren-t. – IAmInPLS