Android Can';无法获取身份验证码
我想使用Rest(Delphi XE7)使用Google Api,方法如下:Android Can';无法获取身份验证码,android,delphi,authentication,oauth,google-api,Android,Delphi,Authentication,Oauth,Google Api,我想使用Rest(Delphi XE7)使用Google Api,方法如下: uses ... {$IF DEFINED(ANDROID)} REST.Authenticator.OAuth.WebForm.FMX; {$ENDIF} {$IF DEFINED(MsWindows)} REST.Authenticator.OAuth.WebForm.Win; {$ENDIF} 该过程在Windows上运行,在该程序更改AuchCode以访问令牌和所有操作之后 proc
uses
...
{$IF DEFINED(ANDROID)}
REST.Authenticator.OAuth.WebForm.FMX;
{$ENDIF}
{$IF DEFINED(MsWindows)}
REST.Authenticator.OAuth.WebForm.Win;
{$ENDIF}
该过程在Windows上运行,在该程序更改AuchCode以访问令牌和所有操作之后
procedure TForm2.OAuth2_GoogleTasks_BrowserTitleChanged(const ATitle: string; var DoCloseWebView: boolean);
begin
if Pos('Success code', ATitle) > 0 then
begin
AuthCode := Copy(ATitle, 14, Length(ATitle));
if (AuthCode <> '') then
begin
editactoken.Text:= AuthCode;
DoCloseWebView := true;
webform.Release;
end;
end;
end;
procedure TForm2.Button59Click(Sender: TObject);
begin
WebForm:=Tfrm_OAuthWebForm.Create(nil);
WebForm.OnTitleChanged := self.OAuth2_GoogleTasks_BrowserTitleChanged;
WebForm.ShowWithURL(OAuth2Authenticator1.AuthorizationRequestURI);
end;
在REST.Authenticator.OAuth.WebForm.Win中,它如下所示:
private
{ Private declarations }
FOnBeforeRedirect: TOAuth2WebFormRedirectEvent;
FOnAfterRedirect: TOAuth2WebFormRedirectEvent;
FOnBrowserTitleChanged : TOAuth2WebFormTitleChangedEvent;
FLastTitle: string; // <-------
FLastURL: string
private
{私有声明}
FOnBeforeRedirect:TOAuth2WebFormRedirectEvent;
FOnAfterRedirect:TOAuth2WebFormRedirectEvent;
FOnBrowserTitleChanged:TOAuth2WebFormTitleChangedEvent;
FLastTitle:string;// Android(安装了Google Play Services)提供了一个本机解决方案,用于使用其他Google API进行身份验证,无需使用web浏览器:
见:
当您希望您的Android应用程序使用用户的
通过HTTP、类和相关API的Google帐户
为您的用户提供安全、一致的选择产品的体验
帐户并检索应用程序的OAuth 2.0令牌
然后,您可以在与的基于HTTP的通信中使用该令牌
未包含在Google Play服务中的Google API服务
库,如Blogger或Translate API
我建议在这方面做一些研究。上面链接的页面还提到了一些(非HTTP)服务的可用性 对我来说,理解如何将上面链接中的代码从java转换为delphi有点困难。没有样品。我也使用这种机制从桌面应用程序访问谷歌硬盘,但无论如何,谢谢你们的澄清。
private
{ Private declarations }
FOnBeforeRedirect: TOAuth2WebFormRedirectEvent;
FOnAfterRedirect: TOAuth2WebFormRedirectEvent;
FOnBrowserTitleChanged : TOAuth2WebFormTitleChangedEvent;
FLastTitle: string; // <-------
FLastURL: string