windows phone 8 - Google oauth api退出问题在Google api.net客户端



我使用的是" google . api . youtube "。v3 Client Library1.8.1.1050 " Windows Phone 8访问API的Nuget包。我能够使用这个API成功地做登录功能。我能够在YouTube API v3上执行某些操作,只有通过登录经过身份验证的谷歌帐户详细信息。我也能够使用这个API从Youtube获得所有提要。现在,我在使用谷歌API V3 oAuth2时面临一个问题。我使用以下代码做登录与谷歌帐户:

UserCredential credential;
using (var stream = new FileStream("clientdata.json", FileMode.Open, FileAccess.Read)){
    credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
    GoogleClientSecrets.Load(stream).Secrets,
    // This OAuth 2.0 access scope allows for read-only access to the authenticated 
    // user's account, but not other types of account access.
    new[] { YouTubeService.Scope.Youtubepartner },
    "user",
    CancellationToken.None);}

使用此代码,我可以成功登录并能够获得所有提要。但是现在我的问题是如何从Windows Phone 8应用程序注销使用谷歌API v3?据我所知,没有方法可以清除这个包中的用户凭据。现在,我正在调用一个web服务

https://accounts.google.com/o/oauth2/revoke?token={访问令牌}

撤销当前的访问令牌,但这没有多大帮助。

如果我能得到任何帮助来解决这个问题,那就太好了。如果有需要修改的地方请告诉我。如果有人能提供如何在Windows Phone中有效使用此API的文档或示例就更好了。

Thanks in advance

现在可以在UserCredential对象上调用

await myUserCredential.RevokeTokenAsync(null);

这将删除用户令牌,他将被要求再次授权。

或者有REST API https://developers.google.com/identity/protocols/OAuth2WebServer#tokenrevoke

https://accounts.google.com/o/oauth2/revoke?token={token}

用户注销后必须清除cookie。要注销用户,SDK中没有任何内置功能。因此,请尝试下面的代码作为注销函数。

private async void logout(object sender, System.Windows.Input.GestureEventArgs e)
{
    WebBrowser wb = new WebBrowser();
    var url = "http://accounts.google.com/Logout";
    wb.Navigate(new Uri(url, UriKind.RelativeOrAbsolute));
    await wb.ClearCookiesAsync();
}

首先,我在我们的问题跟踪器中创建了一个新问题:https://code.google.com/p/google-api-dotnet-client/issues/detail?id=463,希望它将在即将到来的版本中修复。

也请解释为什么"this is not much helpful"。

现在,尝试调用您提到的revoke方法。此外(目前……)我建议创建一个新的UserCredential(使用不同的"用户")和一个新的服务,并让我知道它是否工作

从隔离存储中删除由Google Authentication Library Call创建的文件。使用微软windows手机工具查找该文件的名称。对于Windows phone应用程序,它很可能是-"google . api . auth . oauth2 . responses . tokenresponse -user"。

WebBrowser wb = new WebBrowser();
var url = "http://accounts.google.com/Logout";
wb.Navigate(new Uri(url, UriKind.RelativeOrAbsolute));
await wb.ClearCookiesAsync();
using (IsolatedStorageFile iS = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (iS.FileExists("Google.Apis.Auth.OAuth2.Responses.TokenResponse-user"))
                {
                    iS.DeleteFile("Google.Apis.Auth.OAuth2.Responses.TokenResponse-user");
                }
            }

最新更新