我可以使用web authentication sample登录 Google 。这是代码:
private async void Launch_Click(object sender, RoutedEventArgs e)
{
if(GoogleClientID.Text == "")
{
rootPage.NotifyUser("Please enter an Client ID.", NotifyType.StatusMessage);
}
else if(GoogleCallbackUrl.Text == "")
{
rootPage.NotifyUser("Please enter an Callback URL.", NotifyType.StatusMessage);
}
try
{
String GoogleURL = "https://accounts.google.com/o/oauth2/auth?client_id=" + Uri.EscapeDataString(GoogleClientID.Text) + "&redirect_uri=" + Uri.EscapeDataString(GoogleCallbackUrl.Text) + "&response_type=code&scope=" + Uri.EscapeDataString("http://picasaweb.google.com/data");
System.Uri StartUri = new Uri(GoogleURL);
// When using the desktop flow, the success code is displayed in the html title of this end uri
System.Uri EndUri = new Uri("https://accounts.google.com/o/oauth2/approval?");
DebugPrint("Navigating to: " + GoogleURL);
WebAuthenticationResult WebAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(
WebAuthenticationOptions.UseTitle,
StartUri,
EndUri);
if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success)
{
OutputToken(WebAuthenticationResult.ResponseData.ToString());
}
else if (WebAuthenticationResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp)
{
OutputToken("HTTP Error returned by AuthenticateAsync() : " + WebAuthenticationResult.ResponseErrorDetail.ToString());
}
else
{
OutputToken("Error returned by AuthenticateAsync() : " + WebAuthenticationResult.ResponseStatus.ToString());
}
}
catch (Exception Error)
{
//
// Bad Parameter, SSL/TLS Errors and Network Unavailable errors are to be handled here.
//
DebugPrint(Error.ToString());
}
}
应用程序通过身份验证后,我不确定如何使用文件操作。他们是 Google 提供的一个 .Net 库,但它似乎不适用于 Windows 商店应用程序。
这是通过 http 上传的 doc 文件:
谷歌云端硬盘 API:https ://developers.google.com/drive/manage-uploads
我尝试使用HttpClient 示例,但不确定如何使用从身份验证示例中获得的身份验证令牌。