Link YouTube

The Google Ads API supports linking YouTube videos to your Google Ads account. This guide explains how to use the API to add and remove links to your account.

Videos can be linked to your account in one of two ways, depending on who starts the process, either:

  1. You request that a video is linked to your account. In this scenario, you send a request to a creator, which they must accept in order to establish the link to their video. You can revoke a request that has been extended before it's accepted, and also remove a linked video after it's accepted.
  2. The creator of the video requests that their video is linked to your Google Ads account. You can then choose to accept or reject their request.

The following methods are used in each scenario:

ScenarioActionRemarks
Scenario 1Get the video information from the YouTube APIUse the YouTube API to get the channel_id to send the video link request to, or the video_id of the video you want to link. The video_id can also be pulled from the URL of a video by pulling the 11 characters after "v=".
Create a link requestUse the DataLinkService.CreateDataLink method to create a link request. The status of the DataLink shouldn't be set; the Google Ads API server will set this to REQUESTED upon the successful completion of the API call.
Inspect the status of a requestUse GoogleAdsService.SearchStream or GoogleAdsService.Search to query the data_link resource and inspect its status.
Revoke a requestUse the DataLinkService.UpdateDataLink method to revoke a link request by changing the status of the DataLink from REQUESTED to REVOKED.
Remove a linkUse DataLinkService.RemoveDataLink to remove a linked video.
Scenario 2Retrieve an invitationUse GoogleAdsService.Search or GoogleAdsService.SearchStream to query the data_link resource. Filter for status= PENDING_APPROVAL to find link requests to accept or reject.
Accept or reject a link requestUse the DataLinkService.UpdateDataLink method to update the status of the DataLink to ENABLED to accept or REJECTED to reject the request.

The following common errors can be thrown in this workflow:

Error codeExplanation
DataLinkError.PERMISSION_DENIEDThe customer doesn't have the permission to perform this action.
DataLinkError.YOUTUBE_VIDEO_ID_INVALIDA video link couldn't be created, since the video ID is invalid.