我想在我的移動應用程式中使用 google oauth 授權。我之前已經在測驗控制臺應用程式中實作了這個功能。但是在我在 Xamarin Android 中重新構建代碼后出現了問題。代碼 :
private void _youtubeOAuth()
{
string[] scopes =
{
"https://www.googleapis.com/auth/youtube.readonly",
};
var clientSecrets = new ClientSecrets
{
ClientId = "00000v.apps.googleusercontent.com",
ClientSecret = "GOCS****Jo8EMYq"
};
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
clientSecrets,
scopes,
"user_id",
CancellationToken.None,
new FileDataStore(""))
.Result;
var youtubeService = new YouTubeService(
new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Desktop client 1"
});
var channelsListRequest = youtubeService.Channels.List("contentDetails, snippet");
channelsListRequest.Mine = true;
ChannelListResponse channelsListResponse = channelsListRequest.Execute();
string chanellTitle = channelsListResponse.Items[0].Snippet.Title;
Console.WriteLine(chanellTitle " Subscriptions:");
}
這是臟代碼,但在控制臺應用程式中執行良好。當我嘗試在 Xamarin 中啟動方法時,我捕獲了例外:
無法使用“https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&response_type=code&client_id=****.apps.googleusercontent.com&redirect_uri=http://127.0.0”啟動瀏覽器.1:40031/authorize/&scope=https://www.googleapis.com/auth/youtube.readonly" 用于授權。

我不確定移動應用程式權限中的問題,因為這段代碼執行得很好。
private async void _openBrowser()
{
Uri uri = new Uri("https://accounts.google.com/o/oauth2/v2/auth?access_type=offline&response_type=code&client_id=****.apps.googleusercontent.com&redirect_uri=http://127.0.0.1:40031/authorize/&scope=https://www.googleapis.com/auth/youtube.readonly");
await Browser.OpenAsync(uri, BrowserLaunchMode.SystemPreferred);
}
uj5u.com熱心網友回復:

多年來出現了許多請求支持#984的問題,因此決定不嘗試支持 Xamarin。
在 2018 年 10 月的一次團隊討論中,我們決定不再繼續支持 Xamarin。我們沒有看到證據表明有足夠的使用量來證明我們完全支持 Xamarin 平臺所需的技術作業和基礎設施是合理的。
如果情況發生變化,我們將定期重新審視這一決定。
由于該庫當前處于維護模式,并且當前沒有其他功能正在開發中。我不希望添加這個。
話雖這么說,幾年前我能夠為一個客戶作業,它要求我為它創建自己的授權方法。它填充了憑據,然后創建您自己的 idatastore 實作,它將讀取您的憑據。這可能會讓您了解如何做到這一點。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/462244.html
標籤:C# 安卓 xamarin 谷歌认证 google-api-dotnet-client
上一篇:將子檔案夾上移一級,包括其內容
