我想使用Rest(Delphi XE7)与Google Api一起使用,方法是这样的:

uses
 ...
 {$IF DEFINED(ANDROID)}
    REST.Authenticator.OAuth.WebForm.FMX;
 {$ENDIF}
 {$IF DEFINED(MsWindows)}
    REST.Authenticator.OAuth.WebForm.Win;
 {$ENDIF}


在该程序将AuchCode更改为访问令牌后,所有程序均正常运行,该过程在Windows上正常运行。

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;


但是我遇到了无法在android上复制身份验证代码的麻烦:

android - 无法获取验证码-LMLPHP


Form2.OAuth2_GoogleTasks_BrowserTitleChanged无法正常工作,因为标题未更改;
REST.Authenticator.OAuth.WebForm.FMX中根本没有标题:

        private
{ Private declarations }
FOnBeforeRedirect: TOAuth2WebFormRedirectEvent;
FOnAfterRedirect: TOAuth2WebFormRedirectEvent;
FOnBrowserTitleChanged : TOAuth2WebFormTitleChangedEvent;


FLastURL: string;
public



而在REST.Authenticator.OAuth.WebForm.Win中,它看起来像这样:

            private
     { Private declarations }
    FOnBeforeRedirect: TOAuth2WebFormRedirectEvent;
    FOnAfterRedirect: TOAuth2WebFormRedirectEvent;
    FOnBrowserTitleChanged : TOAuth2WebFormTitleChangedEvent;


    FLastTitle: string;  // <-------
    FLastURL: string



在fmx变体中没有属性webform.lasttitle(在胜利中我可以得到它)
重定向后,LastUrl属性如下所示:“ ......”,但我不明白如何使用它来获取身份验证代码。
尝试使用IFMXClipboardService,但无法从Twebbrowser获取此文本。
Google不允许对lastUrl地址使用Http get方法来获取响应并解析此代码(错误405)。
我读过一些文章,说无法从webbrowser fmx获取html代码,是吗?


有什么想法可以在程序中获取此代码吗?

最佳答案

Android(已安装Google Play服务)为无需其他Web浏览器的其他Google API进行身份验证提供了本机解决方案:

参见https://developers.google.com/android/guides/http-auth


  如果您想让Android应用使用用户的
  通过HTTP,GoogleAuthUtil类和相关API的Google帐户
  为您的用户提供安全一致的选择体验
  帐户并为您的应用检索OAuth 2.0令牌。
  
  然后,您可以在基于HTTP的通信中使用
  Google Play服务未包含的Google API服务
  库,例如Blogger或Translate API。


我建议朝这个方向做一些研究。上面链接的页面还提到了某些(非HTTP)服务的GoogleApiClient

10-07 19:15
查看更多