Google drive api folder permissions










0














I have problem with google drive api v3.
I took google example and I tried. I could read folder content but I did nothing with folder permission.



I received error 403, "Insufficient Permission".
I can't create or read all permissions for the folder.



<?php
require_once __DIR__.'/vendor/autoload.php';

$client = new Google_Client();
$client->setAuthConfig('client_secrets.json');
$client->addScope(Google_Service_Drive::DRIVE);
$client->setAccessType('offline');

if (isset($_SESSION['access_token']) && $_SESSION['access_token'])
$client->setAccessToken($_SESSION['access_token']);
$drive = new Google_Service_Drive($client);

$folderId = '1_ip3-WUs4F6atNdElJ3KHccAV4lI0nLL';

$optParams = array(
'pageSize' => 100,
'fields' => "nextPageToken, files(id,name)",
'q' => "'".$folderId."' in parents"
);

$results = $drive->files->listFiles($optParams);

if (count($results->getFiles()) != 0)
foreach ($results->getFiles() as $file)
echo "Id: " . $file->getId() . " Name: " . $file->getName() . "<br>";



else
$redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php';
header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));


//+!+!+!+!+!+!+!+!+!+! Next code doesn't WORK !+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!//

$fileId = '1UXSg5W-XIX82izGK8uEXXWPUCLcDGRa1';

$userPermission = new Google_Service_Drive_Permission(array(
'type' => 'user',
'role' => 'reader',
'emailAddress' => 'email@gmail.com'
));

$request = $drive->permissions->create($fileId, $userPermission, array('fields' => 'id'));
echo $request;

?>









share|improve this question


























    0














    I have problem with google drive api v3.
    I took google example and I tried. I could read folder content but I did nothing with folder permission.



    I received error 403, "Insufficient Permission".
    I can't create or read all permissions for the folder.



    <?php
    require_once __DIR__.'/vendor/autoload.php';

    $client = new Google_Client();
    $client->setAuthConfig('client_secrets.json');
    $client->addScope(Google_Service_Drive::DRIVE);
    $client->setAccessType('offline');

    if (isset($_SESSION['access_token']) && $_SESSION['access_token'])
    $client->setAccessToken($_SESSION['access_token']);
    $drive = new Google_Service_Drive($client);

    $folderId = '1_ip3-WUs4F6atNdElJ3KHccAV4lI0nLL';

    $optParams = array(
    'pageSize' => 100,
    'fields' => "nextPageToken, files(id,name)",
    'q' => "'".$folderId."' in parents"
    );

    $results = $drive->files->listFiles($optParams);

    if (count($results->getFiles()) != 0)
    foreach ($results->getFiles() as $file)
    echo "Id: " . $file->getId() . " Name: " . $file->getName() . "<br>";



    else
    $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php';
    header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));


    //+!+!+!+!+!+!+!+!+!+! Next code doesn't WORK !+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!//

    $fileId = '1UXSg5W-XIX82izGK8uEXXWPUCLcDGRa1';

    $userPermission = new Google_Service_Drive_Permission(array(
    'type' => 'user',
    'role' => 'reader',
    'emailAddress' => 'email@gmail.com'
    ));

    $request = $drive->permissions->create($fileId, $userPermission, array('fields' => 'id'));
    echo $request;

    ?>









    share|improve this question
























      0












      0








      0







      I have problem with google drive api v3.
      I took google example and I tried. I could read folder content but I did nothing with folder permission.



      I received error 403, "Insufficient Permission".
      I can't create or read all permissions for the folder.



      <?php
      require_once __DIR__.'/vendor/autoload.php';

      $client = new Google_Client();
      $client->setAuthConfig('client_secrets.json');
      $client->addScope(Google_Service_Drive::DRIVE);
      $client->setAccessType('offline');

      if (isset($_SESSION['access_token']) && $_SESSION['access_token'])
      $client->setAccessToken($_SESSION['access_token']);
      $drive = new Google_Service_Drive($client);

      $folderId = '1_ip3-WUs4F6atNdElJ3KHccAV4lI0nLL';

      $optParams = array(
      'pageSize' => 100,
      'fields' => "nextPageToken, files(id,name)",
      'q' => "'".$folderId."' in parents"
      );

      $results = $drive->files->listFiles($optParams);

      if (count($results->getFiles()) != 0)
      foreach ($results->getFiles() as $file)
      echo "Id: " . $file->getId() . " Name: " . $file->getName() . "<br>";



      else
      $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php';
      header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));


      //+!+!+!+!+!+!+!+!+!+! Next code doesn't WORK !+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!//

      $fileId = '1UXSg5W-XIX82izGK8uEXXWPUCLcDGRa1';

      $userPermission = new Google_Service_Drive_Permission(array(
      'type' => 'user',
      'role' => 'reader',
      'emailAddress' => 'email@gmail.com'
      ));

      $request = $drive->permissions->create($fileId, $userPermission, array('fields' => 'id'));
      echo $request;

      ?>









      share|improve this question













      I have problem with google drive api v3.
      I took google example and I tried. I could read folder content but I did nothing with folder permission.



      I received error 403, "Insufficient Permission".
      I can't create or read all permissions for the folder.



      <?php
      require_once __DIR__.'/vendor/autoload.php';

      $client = new Google_Client();
      $client->setAuthConfig('client_secrets.json');
      $client->addScope(Google_Service_Drive::DRIVE);
      $client->setAccessType('offline');

      if (isset($_SESSION['access_token']) && $_SESSION['access_token'])
      $client->setAccessToken($_SESSION['access_token']);
      $drive = new Google_Service_Drive($client);

      $folderId = '1_ip3-WUs4F6atNdElJ3KHccAV4lI0nLL';

      $optParams = array(
      'pageSize' => 100,
      'fields' => "nextPageToken, files(id,name)",
      'q' => "'".$folderId."' in parents"
      );

      $results = $drive->files->listFiles($optParams);

      if (count($results->getFiles()) != 0)
      foreach ($results->getFiles() as $file)
      echo "Id: " . $file->getId() . " Name: " . $file->getName() . "<br>";



      else
      $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/oauth2callback.php';
      header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));


      //+!+!+!+!+!+!+!+!+!+! Next code doesn't WORK !+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!+!//

      $fileId = '1UXSg5W-XIX82izGK8uEXXWPUCLcDGRa1';

      $userPermission = new Google_Service_Drive_Permission(array(
      'type' => 'user',
      'role' => 'reader',
      'emailAddress' => 'email@gmail.com'
      ));

      $request = $drive->permissions->create($fileId, $userPermission, array('fields' => 'id'));
      echo $request;

      ?>






      google-api google-drive-sdk






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 10:21









      Alex

      63




      63






















          1 Answer
          1






          active

          oldest

          votes


















          2














          It may be that wrong permissions have been set when creating the folder, even though you said you did nothing. I do not see the code for creating the folder here, just an ID, which indicates that the folder has already been created.



          I suggest trying to list the permissions using Drive.Permissions.List first. Particularly, look at the type and role or teamDrivePermissionDetails.role properties. See the permissions guide on what operations each role or type can do. You can also visit this documentation on managing sharing in case you need to.






          share|improve this answer




















          • perhaps also worth looking at the scopes of the project. have you obtained sufficient project scope permission for the API to access. Consider adding 'googleapis.com/auth/drive' to the OAUTH scope
            – Peter Scott
            Nov 12 at 16:05










          • Maybe it was a reason for problem. I have changed the scope of the project and now I have to wait couple of days for checking.
            – Alex
            Nov 12 at 17:49










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247778%2fgoogle-drive-api-folder-permissions%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          It may be that wrong permissions have been set when creating the folder, even though you said you did nothing. I do not see the code for creating the folder here, just an ID, which indicates that the folder has already been created.



          I suggest trying to list the permissions using Drive.Permissions.List first. Particularly, look at the type and role or teamDrivePermissionDetails.role properties. See the permissions guide on what operations each role or type can do. You can also visit this documentation on managing sharing in case you need to.






          share|improve this answer




















          • perhaps also worth looking at the scopes of the project. have you obtained sufficient project scope permission for the API to access. Consider adding 'googleapis.com/auth/drive' to the OAUTH scope
            – Peter Scott
            Nov 12 at 16:05










          • Maybe it was a reason for problem. I have changed the scope of the project and now I have to wait couple of days for checking.
            – Alex
            Nov 12 at 17:49















          2














          It may be that wrong permissions have been set when creating the folder, even though you said you did nothing. I do not see the code for creating the folder here, just an ID, which indicates that the folder has already been created.



          I suggest trying to list the permissions using Drive.Permissions.List first. Particularly, look at the type and role or teamDrivePermissionDetails.role properties. See the permissions guide on what operations each role or type can do. You can also visit this documentation on managing sharing in case you need to.






          share|improve this answer




















          • perhaps also worth looking at the scopes of the project. have you obtained sufficient project scope permission for the API to access. Consider adding 'googleapis.com/auth/drive' to the OAUTH scope
            – Peter Scott
            Nov 12 at 16:05










          • Maybe it was a reason for problem. I have changed the scope of the project and now I have to wait couple of days for checking.
            – Alex
            Nov 12 at 17:49













          2












          2








          2






          It may be that wrong permissions have been set when creating the folder, even though you said you did nothing. I do not see the code for creating the folder here, just an ID, which indicates that the folder has already been created.



          I suggest trying to list the permissions using Drive.Permissions.List first. Particularly, look at the type and role or teamDrivePermissionDetails.role properties. See the permissions guide on what operations each role or type can do. You can also visit this documentation on managing sharing in case you need to.






          share|improve this answer












          It may be that wrong permissions have been set when creating the folder, even though you said you did nothing. I do not see the code for creating the folder here, just an ID, which indicates that the folder has already been created.



          I suggest trying to list the permissions using Drive.Permissions.List first. Particularly, look at the type and role or teamDrivePermissionDetails.role properties. See the permissions guide on what operations each role or type can do. You can also visit this documentation on managing sharing in case you need to.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 12 at 6:28









          Jacque

          2916




          2916











          • perhaps also worth looking at the scopes of the project. have you obtained sufficient project scope permission for the API to access. Consider adding 'googleapis.com/auth/drive' to the OAUTH scope
            – Peter Scott
            Nov 12 at 16:05










          • Maybe it was a reason for problem. I have changed the scope of the project and now I have to wait couple of days for checking.
            – Alex
            Nov 12 at 17:49
















          • perhaps also worth looking at the scopes of the project. have you obtained sufficient project scope permission for the API to access. Consider adding 'googleapis.com/auth/drive' to the OAUTH scope
            – Peter Scott
            Nov 12 at 16:05










          • Maybe it was a reason for problem. I have changed the scope of the project and now I have to wait couple of days for checking.
            – Alex
            Nov 12 at 17:49















          perhaps also worth looking at the scopes of the project. have you obtained sufficient project scope permission for the API to access. Consider adding 'googleapis.com/auth/drive' to the OAUTH scope
          – Peter Scott
          Nov 12 at 16:05




          perhaps also worth looking at the scopes of the project. have you obtained sufficient project scope permission for the API to access. Consider adding 'googleapis.com/auth/drive' to the OAUTH scope
          – Peter Scott
          Nov 12 at 16:05












          Maybe it was a reason for problem. I have changed the scope of the project and now I have to wait couple of days for checking.
          – Alex
          Nov 12 at 17:49




          Maybe it was a reason for problem. I have changed the scope of the project and now I have to wait couple of days for checking.
          – Alex
          Nov 12 at 17:49

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53247778%2fgoogle-drive-api-folder-permissions%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Darth Vader #20

          How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

          Ondo