Youtube : Multiple accounts authentication (OAuth) to upload video to single account/channel - ios

I am integrating video upload to Youtube from iOS application.
Steps followed :
Created Google account and enable Youtube data API for the account in developer console.
Created client ID and client secret and incorporated in the application.
Checked out Google API objective C client for Youtube upload which is normally a MAC tool, i just modified for iOS.
Run the application.
It will prompt for Login (OAuth).
Case # 1
Use the same account for Login, which used for creating client ID and
Client secret.
Accept the scopes and assign the authorizer to Youtube service.
GTMOAuth2ViewControllerTouch :
completionHandler:^(GTMOAuth2ViewControllerTouch *viewController,
GTMOAuth2Authentication *auth, NSError *error)
{
self.youTubeService.authorizer = auth;
}
start upload and it working fine.
Case #2
Use Different account for login.
Accept the scopes and assign the authorizer to Youtube service.
GTMOAuth2ViewControllerTouch :
completionHandler:^(GTMOAuth2ViewControllerTouch *viewController,
GTMOAuth2Authentication *auth, NSError *error)
{
self.youTubeService.authorizer = auth;
}
start upload and it causing : Error Domain=com.google.GTLJSONRPCErrorDomain Code=-32602 "The operation couldn’t be completed. (Unauthorized)" UserInfo=0x986abe0 {error=Unauthorized, GTLStructuredError=GTLErrorObject 0x98528d0: {message:"Unauthorized" code:-32602 data:1}, NSLocalizedFailureReason=(Unauthorized)}
Note : If i uses same account (used to create client ID and secret) to login and upload, it is working fine and video is displaying in Youtube.
But whenever trying with other account to upload it causing problem even in Google API objective C client application too.
let me know if i missing any other cases to be consider to do so.
thanks.

You may be doing Auth wrong, or the user may not have a valid connect YouTube channel.
You can check YouTube Direct Lite for iOS project for the best example.

After a day of search/testing, finally found the cause.
There is nothing wrong with my OAuth process.
The cause is other multiple accounts (not the one used to create Client ID and Client Secret) was not having a channel in Youtube.
Solution :
If user account is new to Youtube, then youtube won't have a channel for that account.
User need to create one (that's easy, Youtube itself will alert to create new channel when, My Channel from left side pane is get selected)
If user account have valid channel, then the above "Unauthorized" error won't be happen.

Related

FacebookLogin loginWithReadPermissions does not request any new permissions

Ive previously requested public_profile, user_friends, and email which Facebook will let you use pretty freely in my Swift iOS app but now I'm trying to update the app to request new permissions with loginWithReadPermissions but when it transfers to the login page it just says that I've already granted my app permission and doesn't request the new permissions. Querying the results shows no granted or denied permissions and looking at the Graph Explorer API on the Facebook Developer site shows the same. So I'm looking for suggestions on why my app might not be sending the updated request to the server.
I should note that I'm utilizing the AWS iOS Mobile SDK. I found another answer that overwrites the default Facebook sign in provider to add new permissions to the request but this has the same result.
Also in my output Im seeing the following string which contains all the permissions Im trying to request which makes me think that the request is going out but something else is happening
scope=email%2Cuser_birthday%2Cuser_hometown%2Cuser_friends%2Cpublic_profile%2Cuser_about_me

Youtube Data API - How to avoid Google OAuth redirect URL authorization

Requirement: I am trying to upload videos to my Youtube channel through Youtube Data API for Java. The request is sent from a war file hosted on tomcat container.My application is not for external users and I only use it to upload my own generated videos. With the help of the api documentation and sample youtube code snippets, I have successfully managed to post video on youtube.
Problem: The issue is that whenever I try to run the code, I get prompted for
Please open the following address in your browser:
https://accounts.google.com/o/oauth2/auth?client_id=&redirect_uri=http://localhost:8080/Callback&response_type=code&scope=https://www.googleapis.com/auth/youtube.upload
Since I run this code on a remote server, it is not possible for me to always open this URL on the browser. Since I have registered my web app in Google Console, and got a pair of Client ID and Secret and a JSON file, so Youtube must allow me to publish videos by default to atleast my channel, isin't it?
I have used the Auth.java file(provided in youtube java code samples) and the following code is where this thing happens.
// Authorize.
return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user#.com");
LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();
Please help here as this is really eating up a lot of my development time.
You should only need to authenticate your code once. When your code is authenticated you get a refresh token back. the refresh token will then allow you to get a new access token the next time your code runs.
There is no service account authentication for the YouTube api. Your code has to be authenticated by you the first time in order to get that refresh token.
I am not a java programmer but from a quick check of the documentation it looks quite similar to what I do in.net. You need to create a datastore to to store the first refreshh token then you should be able to run your code in the future with out needing to authenticate it again.

Allowing Google Service Account YouTube Upload Access via API v3

I want to automatically upload videos to YouTube without user involvement so I've created a service account, jumped through the hoops, all was looking great, then the upload, chunk one, is attempted and my code bombs with this Google_Exception exception:
"Failed to start the resumable upload (HTTP 401: youtube.header, Unauthorized)"
I then dug and found on the YouTube API v3 error information:
https://developers.google.com/youtube/v3/docs/errors
"This error is commonly seen if you try to use the OAuth 2.0 Service Account flow. YouTube does not support Service Accounts, and if you attempt to authenticate using a Service Account, you will get this error."
Is this correct? I cannot use a service account to upload video to YouTube automatically?
(that was a waste of a couple of days hard work!)
Yes, it is correct.
The way forward is to do a manual authorisation and grab the resultant 'refresh token' and then use that for any automated uploads.
Ensure to add the refresh token to the PHP Google_Client object prior to any other action.
I am now automatically uploading to YouTube.
For anyone attempting to do this today, be aware that any uploads will be set as "Private (Locked)" if they are uploaded using the API unless/until the app is submitted for verification and approved.
https://github.com/porjo/youtubeuploader/issues/86
YouTube requires verification of the OAuth App/credentials used for upload, otherwise the video will be locked as Private.
It's possible to get an app approved, but if you're doing a personal project, it's less likely.
More: https://github.com/porjo/youtubeuploader/issues/86
Yes you can use Service Accounts for Youtube. One way is to add the service account to a CMS where the content owner is part of. When you retrieve an access_token for the Service Account, you can work with the content owners videos.
Looks like this, using Javascript and a npm package:
import { google } from 'googleapis';
const youtube = google.youtube('v3');
const fetchYoutubeData = async (keyfile, scopes) => {
const auth = new google.auth.GoogleAuth({
credentials: keyfile,
scopes,
});
const accessToken = await auth.getAccessToken();
const { data } = await youtube.videos.list({
part: ['snippet'],
id: 'YOUR_VIDEO_ID',
access_token: accessToken
});
return data;
}
Note that the keyfile is the JSON you downloaded from Gcloud when creating the service accounts keys. NOT the path pointing to the file! If you want to use path, use this instead:
const auth = new google.auth.GoogleAuth({
keyFile: 'PATH_TO_KEYFILE_IN_FILE_SYSTEM',
scopes: ['READ_STUFF', 'WRITE_STUFF'],
});
Further reading on server-server authentication using Oauth2

Update thumbnail without asking for google login - Youtube API V3.0 - OAuth2.0 -

My goal is quite simple : Use php files that will log on my youtube account and upload custom thumbnails.
I already successfully used Youtube API V2 to upload videos with no problem,
but the V3 requires OAuth2.0, and I can't found a way to avoid my server keeps ask me "Please login from your google account"
I use the example from the official place, here :
And created my OAuth token (tried web application and service) but it keeps ask me to log in...
I only want the php files to log on alone, because I want to share them to some friends that will be able to change thumbnails without having a google acount or knowing my youtube/google password.
You can do so by getting a refresh token from OAuth2 Playground and setting it in your youtube object.
Here it explains a little more.
And a step by step video.
Thank you Ibrahim, it solved my problem :) !
Except you didn't mentionned that I had to use $client->refreshToken('Refresh Token'); and then start the conditional : if ($client->getAccessToken()) { [...] . Very important to the others one who could encounter the problem : You need to use google developper console https://cloud.google.com/console and specify in APIs & Ath > Credentials the exact adress of your PHP script, and set a product name and email address in Consent Screen.

iPhone Google+ Login and OAuth2 in Backend

Looking the tutorial of using Google+ SDK for iOS in this link, I am able to configure the project and grant my application to obtain an access token. However, I do not want to consume the token in the device to obtain its name, email, etc. I want to obtain a temporal access code (that can be changed for an OAuth2 token) or a id token as I do in my Android application. This is called by google the cross-client identity.
The idea is that the backend server will received this exchange code and will generate the access token to fetch the user profile, email, etc. Then the user is registered with this information. However the access token being generated by the iOS app can be only consumed by the application itself, since the application id used is the id of the iOS application. I have tried to change application id with the server application id, but then it is thrown a redirect_uri_mismatch.
Trying to consume the access token directly in the server will provoke a Google_OAuth_Exception, as the server client id is not equal to the application client id.
I have another approach running based on opening a web page, but I wanted to use the native Google+ login process.
Any idea?
We are working on this feature. This will allow the application to get a "code" that you can send to your server to store offline access.
Sorry you'll have to wait a couple of weeks (sorry don't have an exact date).
Naveen's answer is correct, but if you just need basic profile information and email address you can use the id token instead. This will include the email address (as long as you requested the email scope), and the user ID which can be used to query for public profile information from the Google+ API, without needing to pass a code or access token. Retrieving the ID token is really easy
[GPPSignIn sharedInstance] setHomeServerClientID:#"911581857976.apps.googleusercontent.com"];
- (void) finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error {
if (error) {
NSLog(#"Error: %#", error);
return;
}
NSLog(#"ID Token: %#", [[GPPSignIn sharedInstance] idToken]);
}
I wrote up a longer example in a blog post a while back, which might help: http://www.riskcompletefailure.com/2013/11/client-server-authentication-with-id.html
Quick answer might be to configure additional redirect URLs in the Cloud Console.
As of today this is available: https://developers.google.com/+/mobile/ios/sign-in#enable_server-side_api_access_for_your_app

Resources