Google Drive PHP SDK guarda un archivo sin título

I'm using the following function to insert a file:

function insertFile($service, $title, $description, $parentId, $mimeType, $filename) {
  $file = new DriveFile();
  $file->setTitle($title);
  $file->setDescription($description);
  $file->setMimeType($mimeType);
  if ($file->parentId != null) {
    $parentsCollectionData = new DriveFileParentsCollection();
    $parentsCollectionData->setId($file->parentId);
    $file->setParentsCollection(array($parentsCollectionData));
  }
  try {
    $datafile = file_get_contents($filename);
    $createdFile = $service->files->insert($file, array(
      'data' => $datafile,
      'mimeType' => $mimeType,
    ));
    print_r($datafile);
  return $createdFile;
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }}

The function uploads the file, but without a title. It creates an "Untitled" file in my Google Drive. I'm using a v2 of API.

print_r($file):

DriveFile Object
(
[mimeType] => text/plain
[thumbnailLink] => 
[__labelsType:protected] => DriveFileLabels
[__labelsDataType:protected] => 
[labels] => 
[__indexableTextType:protected] => DriveFileIndexableText
[__indexableTextDataType:protected] => 
[indexableText] => 
[etag] => 
[lastModifyingUserName] => 
[writersCanShare] => 
[id] => 
[title] => test.txt
[ownerNames] => 
[sharedWithMeDate] => 
[lastViewedByMeDate] => 
[__parentsType:protected] => ParentReference
[__parentsDataType:protected] => array
[parents] => 
[exportLinks] => 
[originalFilename] => 
[description] => Description
[editable] => 
[kind] => 
[quotaBytesUsed] => 
[fileSize] => 
[createdDate] => 
[md5Checksum] => 
[embedLink] => 
[alternateLink] => 
[permissionsLink] => 
[modifiedByMeDate] => 
[downloadUrl] => 
[__userPermissionType:protected] => Permission
[__userPermissionDataType:protected] => 
[userPermission] => 
[fileExtension] => 
[selfLink] => 
[modifiedDate] => 
)

print_r($createdFile):

Array
(
    [kind] => drive#file
    [id] => 0B7fGO53dEJzbUVJwVEFRc09PMkk
    [etag] => "ia2FSHMEjvcFQvtI43H5NSXK_wk/MTM0MTI1MjU5MzA5Nw"
    [selfLink] => https://www.googleapis.com/drive/v2/files/0B7fGO53dEJzbUVJwVEFRc09PMkk
    [alternateLink] => https://docs.google.com/file/d/0B7fGO53dEJzbUVJwVEFRc09PMkk/edit
    [permissionsLink] => https://www.googleapis.com/drive/v2/files/0B7fGO53dEJzbUVJwVEFRc09PMkk/permissions
    [title] => Untitled
    [mimeType] => multipart/related; boundary=1411182904
    [labels] => Array
        (
            [starred] => 
            [hidden] => 
            [trashed] => 
            [restricted] => 
            [viewed] => 1
        )

    [createdDate] => 2012-07-02T18:09:53.402Z
    [modifiedDate] => 2012-07-02T18:09:53.097Z
    [modifiedByMeDate] => 2012-07-02T18:09:53.097Z
    [lastViewedByMeDate] => 2012-07-02T18:09:53.097Z
    [parents] => Array
        (
            [0] => Array
                (
                    [kind] => drive#parentReference
                    [id] => 0ALfGO53dEJzbUk9PVA
                    [selfLink] => https://www.googleapis.com/drive/v2/files/0B7fGO53dEJzbUVJwVEFRc09PMkk/parents/0ALfGO53dEJzbUk9PVA
                    [parentLink] => https://www.googleapis.com/drive/v2/files/0ALfGO53dEJzbUk9PVA
                    [isRoot] => 1
                )

        )

    [downloadUrl] => https://doc-14-4c-docs.googleusercontent.com/docs/securesc/6eprdcqtdmlpnd2gmvdr6jlnlagf8s6i/9fqrnka0tci3gs14tff8ur996h1b74ip/1341252000000/15694289178108491958/15694289178108491958/0B7fGO53dEJzbUVJwVEFRc09PMkk?h=16653014193614665626&e=download&gd=true
    [userPermission] => Array
        (
            [kind] => drive#permission
            [etag] => "ia2FSHMEjvcFQvtI43H5NSXK_wk/9STkNeCmz61YXorH3hoJimnEgfM"
            [id] => current
            [role] => owner
            [type] => user
        )

    [originalFilename] => Untitled
    [fileExtension] => 
    [md5Checksum] => 3e7959340ef7f8a8d24e5b9ad3daafe8
    [fileSize] => 407
    [quotaBytesUsed] => 407
    [ownerNames] => Array
        (
            [0] => Myszczuk
        )

    [lastModifyingUserName] => Myszczuk
    [editable] => 1
    [writersCanShare] => 1
)

preguntado el 01 de julio de 12 a las 19:07

Could you show us the result of print_r($file); y print_r($createdFile);? Also, are you using v1 or v2 of the API? -

Not sure what's wrong, I'm using the code snippet provided aquí (slightly different from what you're using) and it works perfectly for me (the title is correctly set)... Can you make sure you're using the latest version of the PHP client library (sync from the repo)? -

1 Respuestas

Just do what Alain said, update or checkout the newest client library de Google.

Respondido 02 ago 12, 22:08

Aquí el enlace: código.google.com/p/google-api-php-client/source/browse/trunk/src/… - Because sometimes, the new release isn't located where you think. - vicrabb

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.