Elijas / auto-youtube-subscription-playlist-2

Script automatically adds videos to playlists from Youtube channels and/or subscriptions (Youtube Collections alternative).
MIT License
252 stars 55 forks source link

Cannot update playlist for brand account using personal account #51

Open godspeedyou opened 5 years ago

godspeedyou commented 5 years ago

I followed the instructions, but couldn't execute the second step completely:

2. Allow the Sheets to access Youtube:
  * Then, Google Developers Console / Youtube Data API / Enable API, close the tab, go back to Script Editor and click OK

I can't find any Google Developers Console in the Resources / Advanced Google Services dialog. According to https://developers.google.com/apps-script/guides/services/advanced#enabling_advanced_services that option is available for a standard GCP project (or an older default GCP project that was created prior to April 8, 2019).

Nonetheless I tried to "Update Playlists" in the sheet document and this is the error message in the debug sheet:

Mon Oct 28 16:19:57 EET 2019 Couldn't update playlist with video (5Aq7jyS8AAU), ERROR: Beim API-Aufruf von "youtube.playlistItems.insert" ist dieser Fehler aufgetreten: Forbidden

Sorry for the German log message. It means something like Couldn't update playlist with video (5Aq7jyS8AAU), ERROR: The following error occured at api call "youtube.playlistItems.insert": Forbidden

victorjzsun commented 5 years ago

I removed that second step, as you're right, it is default now.

Regarding the error, according to documentation, the Forbidden error occurs when either The playlist already contains the maximum allowed number of items or The request is not properly authorized to insert the specified playlist item. Can you please check both of these?

godspeedyou commented 5 years ago

The new (target) playlist was empty. How do I check the proper authorization?

victorjzsun commented 5 years ago

As in make sure that you own the playlist (there might be some conflict if you're trying to add to another user's playlist). Make sure that the playlist ID you put into the first column of the sheet does indeed point to the right playlist by going to the link https://www.youtube.com/playlist?list=[yourplaylistIDhere] replacing [yourplaylistIDhere] with the actual ID.

victorjzsun commented 5 years ago

I've also pushed a new change to the sheets script (to log more details on API fail errors) so if you could update your script in the script editor and post the result, that'd be great.

godspeedyou commented 5 years ago

Thanks for the administration.

I copied the sheet freshly from the github starting page, granted access and the script ran. It failed with the following error.

Tue Nov 05 22:46:43 EET 2019 Acquired 1 videos
Tue Nov 05 22:46:43 EET 2019 Couldn't update playlist with video (XB8sV_DMFDE), ERROR: Message: [API call to youtube.playlistItems.insert failed with error: Forbidden] Details: {"message":"Forbidden","code":403,"errors":[{"domain":"youtube.playlistItem","reason":"playlistItemsNotAccessible","message":"Forbidden"}]}
Tue Nov 05 22:46:43 EET 2019 Added 0 videos to playlist. Error for 1 videos.

See the attachments for my setup.

Screenshot_20191105_215159 Screenshot_20191105_215255

victorjzsun commented 5 years ago

One thing I'm noting is that the account you're using for the sheet is not the same as the YT account with the playlist (Purple A vs Dog profile icon). Please use the same account as the one that owns the playlist since there might be some complications with using a different account to add videos

godspeedyou commented 5 years ago

That may be the issue. However, the dog profile is my brand account (under the A account) which I've been using for several years and I'm kind of dependent on it. I'd like to avoid a migration to the A account, since I've been using the dog account for many years (playlists, subscriptions, comments and so on are connected to it). I'm going to verify that this is the problem and think about migrating. On the other hand I'd appreciate it very much, if you could find a way to support brand accounts.

victorjzsun commented 5 years ago

That's interesting, and it seems like the reason why it's giving a forbidden error. Brand accounts are completely separate from the personal accounts associated with them, so permissions are not transferable.

According to this post, you can try logging into Google Drive/Sheets using that brand account and run the script under that account instead of the "A" account. This will be a temporary solution until I can figure out exactly how permissions work between playlists and if I can find a better solution than switching accounts. I'll see what I can do.

godspeedyou commented 5 years ago

I have the feeling the StackOverflow answer is outdated. I can't choose Google Drive as an product at https://myaccount.google.com when signed in as my brand. And I haven't found a way yet to log in with the mentioned @pages.plusgoogle.com address to Google Drive directly. It tells me I have the wrong password, when I'm using the A account's password. I contacted the StackOverflow user for advice.

godspeedyou commented 4 years ago

I have the feeling the StackOverflow answer is outdated. I can't choose Google Drive as an product at https://myaccount.google.com when signed in as my brand. And I haven't found a way yet to log in with the mentioned @pages.plusgoogle.com address to Google Drive directly. It tells me I have the wrong password, when I'm using the A account's password. I contacted the StackOverflow user for advice.

I can't find a way to login to google drive with the brand account. I assume google scrapped this feature together with google plus.

trenthm commented 4 years ago

Not sure if this is helpful, but it turned out to be really easy to just move my YouTube brand account to a personal Google. Then the script worked great (minus hitting my quota). Thanks for making this tool.

YouTube Help: Move your YouTube channel to another account

jca2112 commented 4 years ago

I tried the method of generating a refresh token as mentioned in this Stackoverflow post about YouTube APIs, but I am a novice with regards to scripting, working with APIs, etc.

How would I incorporate a generated refresh token into this script to make it work for a YouTube brand account?

victorjzsun commented 4 years ago

That would be pretty difficult and hard to automate without creating a whole new standalone app. I was able to generate a token for a brand account and then use that token to request data from an API, but I cannot do so using a google app such as Google Apps Script, since such an app restricts the caller of the script to be the main account and not a brand account. Basically, since google doesn't allow anyone to sign into a script with a brand account, we'd need to create a whole sign-in architecture that allows for brand accounts.

For anyone who still wants to dive deeper into this issue, here's the process for creating a brand account token:

In terms of how to use this token, at least to test if it works, just send a request to any Google API with an auth header with your token and it should work. To run an Apps Script, the only way I can see is by using something like clasp to run the script remotely using a certain set of credentials (your generated token), but I have yet to see if this works.

victorjzsun commented 4 years ago

Long story short, if we wanted to do something about it, we might as well be Google employees

rid-x commented 4 years ago

Hi, here is the solution https://stackoverflow.com/a/64902884/7484338