How to Put a Video on Google Slides from Your Phone

blog 2025-02-09 0Browse 0
How to Put a Video on Google Slides from Your Phone

Google Slides is a powerful tool for creating presentations and sharing them with others. However, if you want to include videos in your presentation, it can be challenging to do so directly from your phone. Fortunately, there’s an easy way to add videos to your Google Slides presentation using the YouTube API. Here’s how you can do it:

Step 1: Enable the YouTube API

First, you need to enable the YouTube Data API v3 in your Google Cloud Console. This will give you access to the necessary endpoints and credentials needed to interact with YouTube.

Step 2: Create a Service Account

Next, create a new service account in your Google Cloud Console. This service account will act as an intermediary between your app and the YouTube API.

Step 3: Download the JSON Key File

After creating the service account, download the JSON key file that contains all the required credentials.

Step 4: Install the YouTube API Library

Install the YouTube API library for Python using pip. Open your terminal or command prompt and run the following command:

pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib

Step 5: Write the Code to Add a Video to Google Slides

Now, write a script to authenticate with the YouTube API and upload a video to your Google Drive, which can then be added to your Google Slides presentation.

Here’s a simple example of how you might do this:

from __future__ import print_function
import os.path
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.http import MediaFileUpload

# If modifying these SCOPES, delete the file token.json.
SCOPES = ['https://www.googleapis.com/auth/youtube.upload']

def main():
    creds = None
    # The file token.json stores the user's access and refresh tokens, and is
    # created automatically when the authorization flow completes for the first time.
    if os.path.exists('token.json'):
        creds = Credentials.from_authorized_user_file('token.json', SCOPES)
    # If there are no (valid) credentials available, let the user log in.
    if not creds or not creds.valid:
        if creds and creds.expired and creds.refresh_token:
            creds.refresh(Request())
        else:
            flow = InstalledAppFlow.from_client_secrets_file(
                'credentials.json', SCOPES)
            creds = flow.run_local_server(port=0)
        # Save the credentials for the next run
        with open('token.json', 'w') as token:
            token.write(creds.to_json())

    service = build('youtube', 'v3', credentials=creds)

    # Upload a video to Google Drive
    video_name = "my_video.mp4"
    media = MediaFileUpload(video_name, mimetype='video/mp4')
    request = service.videos().insert(part="snippet,status", body={"snippet": {"title": "My Slide Show"}, "status": {"privacyStatus": "public"}}, media_body=media)
    response = request.execute()

    # Get the ID of the uploaded video
    video_id = response['id']
    
    # Now use the video ID to insert into your Google Slides presentation
    # Assuming you have already inserted the slide where you want to add the video
    
    # Replace placeholders with actual values
    presentation_id = "your_presentation_id"
    slide_index = 1  # Adjust index based on your needs
    
    # Insert the video into the slide
    insertion_point = f"/slides/{presentation_id}/slides/{slide_index}/shapes/0/video/{video_id}"
    
    # Call the method to insert the video into the slide
    service.presentations().batchUpdate(presentationId=presentation_id, body={"requests":[{"insertVideoAtPosition":{"position":"INSERT_BEFORE","index":slide_index,"point":{}}}]}).execute()

This script uploads a video named my_video.mp4 to your Google Drive and inserts it into the second slide of your Google Slides presentation.

Conclusion

By leveraging the YouTube API, you can easily integrate videos into your Google Slides presentations without having to manually copy and paste video files. This method ensures that your content remains organized and accessible while also providing a seamless viewing experience for your audience.


Q&A

  1. What is the purpose of enabling the YouTube API?

    • To gain access to the YouTube Data API v3, allowing you to interact with YouTube services programmatically.
  2. Why do I need to create a service account?

    • A service account provides a secure way to authenticate requests made to the YouTube API on behalf of your application.
  3. Where can I find the JSON key file for my service account?

    • After setting up your service account, you can download the JSON key file from the Google Cloud Console under the “Credentials” section.
  4. Is there any risk involved in using the YouTube API?

    • Yes, like any third-party service, there could be risks such as security vulnerabilities or data loss. Always ensure you follow best practices for securing your API keys and credentials.
TAGS