External Software
— What can you do?  — Everything!
  1. Main
  2. /
  3. Google Apps Script
  4.   5 min

Accessing Google Docs without a Gmail Account using Google Apps Script

  •   Mikhail Krotov
  •   May 1st, 2023
  •   23

As a Google Apps Scripts expert and JavaScript programmer, I understand the importance of being able to access Google Docs without a Gmail account. Thankfully, Google Apps Script allows users to access and manipulate Google Drive files without the need for a Gmail account.

In this tutorial, I will guide you through the steps you need to take to access Google Docs without a Gmail account using Google Apps Script.

Step 1: Create a Service Account

To access Google Docs without a Gmail account, you need to create a service account. A service account is a special type of Google account that allows you to access Google APIs programmatically.

Here are the steps to create a service account:

  1. Go to the Google Cloud Console and sign in with your Gmail account.
  2. Click on the project drop-down and select or create the project you want to use for your application.
  3. Click on the Navigation menu and select APIs & Services > Dashboard.
  4. Click on the + ENABLE APIS AND SERVICES button.
  5. Search for Google Drive API and enable it.
  6. Click on the Create Credentials button and select Service account key.
  7. Enter a name for your service account, select the role for your service account, and choose the JSON key type.
  8. Click on the Create button to download your JSON key file.

Step 2: Set Up the Google Drive API Client

After creating your service account, the next step is to set up the Google Drive API client.

Here are the steps you need to follow to set up the Google Drive API client:

  • Open your Google Sheets or Docs document.
  • Click on the Tools menu and select Script Editor.
  • In the Script Editor, click on the Resources menu and select Libraries.
  • In the Libraries window, paste the following script ID: MwF-ytLfYVtjqu9tXOiij1OvLJSOwwPT7
  • From the version drop-down, select the latest version.
  • Click on the Save button.

Step 3: Write the Code

To access Google Docs without a Gmail account, you need to write a code using Google Apps Script.

Here is an example of the code you can use:

function getGoogleDoc() {
    var key = "YOUR_KEY_HERE";
    var service = getService();
    if (service.hasAccess()) {
        var url = "https://docs.google.com/document/d/" + key + "/export?format=pdf";
        var response = UrlFetchApp.fetch(url, {
            headers: {
                'Authorization': 'Bearer ' + service.getAccessToken()
            }
        });
        var content = response.getBlob();
        DriveApp.createFile(content);
    } else {
        var authorizationUrl = service.getAuthorizationUrl();
        Logger.log('Open the following URL and reauthorize the application: %s', authorizationUrl);
    }
}

function getService() {
    return OAuth2.createService('Service Account')
        .setTokenUrl('https://accounts.google.com/o/oauth2/token')
        .setPrivateKey(YOUR_PRIVATE_KEY)
        .setClientId(YOUR_CLIENT_ID)
        .setCache(CacheService.getUserCache())
        .setPropertyStore(PropertiesService.getUserProperties())
        .setScope('https://www.googleapis.com/auth/drive.file');
}

Step 4: Run the Code

After writing the code, the final step is to run it.

Here are the steps to run the code:

  1. Save the code in the Script Editor.
  2. Click on the Run menu and select getGoogleDoc.
  3. Review the authorization window and grant the necessary permissions.
  4. Wait for the script to finish running.
Tags
  • access
  • account
  • api
  • Apps
  • CacheService
  • Client
  • code
  • create
  • Drive
  • Expert
  • Gmail
  • Google
  • Javascript
  • Manipulate
  • OAuth2
  • PropertiesService
  • Run
  • script
  • Service
  • tutorial
←Google Ads Smart Bidding Strategies: Benefits and Best PracticesPrevious article
→Google Ads: How to See if Display Network or Search Network Produced Conversions?Next article

Related

Automating YouTube Descriptions with Google Apps Script
As a content creator on YouTube, uploading videos and managing channel details can often become a tedious task.
  •   17
  •   2023
What can you do with Google Apps Script?
Google Apps Script is a powerful tool that allows you to automate tasks and customize your Google Workspace apps like Sheets, Docs, and Slides.
  •   18
  •   2023
Deleting Duplicates in Google Drive with Google Apps Script
Google Drive is a great tool for storing and organizing files, but it can be cumbersome to manage and de-duplicate files.
  •   16
  •   2023
How to Create a New Library with Google Apps Script
Google Apps Script is a powerful tool for automating tasks and integrating different Google services together.
  •   11
  •   2023

Popular

How to execute third-party code in Google Ads?
How to use ChatGPT for website accessibility design?
Google Ads Conversion Tracking Tags: Why You Need Them and How to Set Them Up?
Why Are Target CPA Bidding Campaigns Limited by Budget Frequently in Google Ads?
Understanding the Role of Document Features in SEO
How to Add Rule-Based Audiences to Google Ads Campaigns for Effective Targeting?
How to Create Amazing SEO Dashboards to Impress Your Clients
Sitelinks in Yandex.Direct and Google Ads

Tools

  • Phrase processing
  • Phrase Generator/Combinator
  • WP TagGen

Other

  • Word lists
  • World country codes
  • Charity

Categories

  • AI & ML
  • Analytics
  • Contextual advertising
  • Development
  • Google Ads
  • Google Ads Scripts
  • Google Analytics
  • Google Apps Script
  • SEO
  • Yandex.Direct

Archive

  • May 2023
  • April 2023
  • March 2023
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • May 2016
  • January 2016
  • November 2015
  • August 2015
  • July 2015
  • May 2015
  • March 2015
  • February 2015
  • December 2014
  • November 2014
  • September 2014
  • May 2014
  • April 2014

Search

  •   RSS
  •   GitHub
  •   Telegram
  •   Фибулист
  •   Limitation of liability
  •   Privacy policy