Я пытаюсь использовать Google Sign-In в Xamarin для создания экземпляра YoutubeService. На данный момент я могу получить GoogleSignInAccount с этой функцией:
public void Login()
{
if(account != null)
{
CreateYoutube();
return;
}
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DefaultSignIn)
.RequestServerAuthCode("112086459272-o965mju8hjqqr1fq333g3am9hqrm650e.apps.googleusercontent.com")
.RequestEmail()
.RequestScopes(new Scope(YouTubeService.Scope.Youtube))
.Build();
googleClient = new GoogleApiClient.Builder(this)
.EnableAutoManage(this, this)
.AddApi(Auth.GOOGLE_SIGN_IN_API, gso)
.Build();
OptionalPendingResult silentLog = Auth.GoogleSignInApi.SilentSignIn(googleClient);
if (silentLog.IsDone)
{
Console.WriteLine("&Casting silentlog to google account");
GoogleSignInResult result = (GoogleSignInResult)silentLog.Get();
if (result.IsSuccess)
{
account = result.SignInAccount;
CreateYoutube();
}
}
StartActivityForResult(Auth.GoogleSignInApi.GetSignInIntent(googleClient), 1598);
}
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data)
{
base.OnActivityResult(requestCode, resultCode, data);
if(requestCode == 1598)
{
GoogleSignInResult result = Auth.GoogleSignInApi.GetSignInResultFromIntent(data);
if (result.IsSuccess)
{
account = result.SignInAccount;
CreateYoutube();
}
}
}
Он работает нормально, и я могу получить профиль пользователя, но я нашел единственный способ создать экземпляр REST Api (например, YouTube) с помощью класса GoogleAccountCredential (из документа здесь: https://developers.google.com/android/guides/http-auth).) Вот код, который я хочу использовать:
void CreateYoutube()
{
GoogleAccountCredential credential = GoogleAccountCredential.UsingOAuth2(
this /*Context*/,
YouTubeService.Scope.Youtube);
credential.SelectedAccount = account;
YouTubeService service = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential
});
}
но я не могу найти API, которые содержат GoogleAccountCredential в Xamarin. Есть ли другой способ создать сервис YoutubeService, используя oauth или API, которые покрывают класс GoogleAccountCredential?
Не стесняйтесь спрашивать меня, не понимаете ли вы что-то в моем вопросе.
Спасибо за прочтение,
Тристан Ру