Activity Forums Salesforce® Discussions Getting trouble to send document to google drive File/Folder in Salesforce

  • Getting trouble to send document to google drive File/Folder in Salesforce

    Posted by Deepak Pandey on January 16, 2018 at 12:42 pm

    Hi,

    My requirement, I have Visualforce page where

    1- I can attach a document and send to my google drive.

    2- I can get all the folder from the google drive and show in VF page.

    1st one I did successfully but in case of the 2nd point I am getting 'Forbidden' error.

    Something I missed please guide me-

    http objHttp = new http();
    Google_Auth_Detail__c tmpGD = [select id,Access_Token__c,Authorization_Code__c,Client_Id__c,Secret_Code__c,Expire_In__c,Refresh_Token__c,Scope__c,Token_Type__c from Google_Auth_Detail__c limit 1];
    Http http = new Http();
    HttpRequest req = new HttpRequest();
    req.setMethod('GET');
    //req.setEndpoint('https://www.googleapis.com/drive/v2/files');
    req.setEndpoint('https://www.googleapis.com/drive/v3/files/0B_QE5jslfxO6clpiRWRnOXpFR00?alt=media');
    req.setHeader('Authorization',tmpGD.Access_Token__c );
    //HttpResponse resp = http.send(req);
    HttpResponse res;
    res = objHttp.send(req);
    system.debug(res.getStatusCode()+'......'+res.getStatus()+'....res.........'+res.getBody());

     

    This is my method to get from google drive.

    Deepak Pandey replied 6 years, 2 months ago 2 Members · 2 Replies
  • 2 Replies
  • Shubham

    Member
    January 16, 2018 at 2:18 pm

    Hello Deepak,

    After reviewing your code i found that you are not using "Bearer" in your header. Try changing your authorization header as below and run your code again.

    req.setHeader('Authorization','Bearer '+tmpGD.Access_Token__c );

    If still error persists then try to check "Allow users to install Google Drive apps" option is enabled by going to Google Drive setting. We also receive "Forbidden" error if this option is disabled.

    Let me know if this fixes the issue.

  • Deepak Pandey

    Member
    January 16, 2018 at 3:35 pm

    Thanks for reply. Above mentioned object , I am holding access token with bearer. I checked it and I enabled the api for this. In debug it’s showing file accessibility problem. But i am not found any solution.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos