如何在Flex移动应用程序中集成谷歌+

编程入门 行业动态 更新时间:2024-10-17 23:33:20
本文介绍了如何在Flex移动应用程序中集成谷歌+的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

任何人都知道如何在Flex移动应用集成谷歌+。虽然我试图与谷歌+越来越像文本=错误#2032错误的验证:流错误网址:accounts.google/o/oauth2/auth?response%5Ftype=$c$c&redirect%5Furi=urn%3Aietf%3Awg%3Aoauth%3A2%2E0%3Aoob&client%5Fid ......ErrorID中= 2032。网址: accounts.google/o/oauth2/auth 。

Anybody know how can integrate google+ in a flex mobile application. While i tried to authenticate with google+ getting an error like text="Error #2032: Stream Error. URL: accounts.google/o/oauth2/auth?response%5Ftype=code&redirect%5Furi=urn%3Aietf%3Awg%3Aoauth%3A2%2E0%3Aoob&client%5Fid ..." errorID=2032]. URL: accounts.google/o/oauth2/auth.

推荐答案

这是你的幸运日,因为我知道如何做到这一点: - )

It's your lucky day, because I know how to do it :-)

该文档是使用OAuth 2.0安装的应用程序,你会得到从访问令牌网页标题。

The doc is Using OAuth 2.0 for Installed Applications and you get the access token from the web page title.

下面是我的看法和我的应用程序的截图和Google+的API控制台:

Below is my View and a screenshot of my app and the Google+ API console:

<?xml version="1.0" encoding="utf-8"?> <s:View xmlns:fx="ns.adobe/mxml/2009" xmlns:s="library://ns.adobe/flex/spark" viewActivate="openSWV(event)" viewDeactivate="closeSWV(event)" title="Getting data..."> <s:layout> <s:VerticalLayout/> </s:layout> <fx:Script> <![CDATA[ import flash.media.StageWebView; private static const APP_ID:String = 'XXXXXXXXX.apps.googleusercontent'; private static const APP_SECRET:String = 'XXXXXXXXXXXXXXXXXXX'; private static const APP_URL:String = 'urn:ietf:wg:oauth:2.0:oob'; private static const AUTH_URL:String = 'accounts.google/o/oauth2/auth?'; private var _swv:StageWebView = new StageWebView(); private function openSWV(event:ViewNavigatorEvent):void { _swv.addEventListener(Event.COMPLETE, extractAccessToken); _swv.addEventListener(LocationChangeEvent.LOCATION_CHANGE, extractAccessToken); _swv.addEventListener(IOErrorEvent.IO_ERROR, closeSWV); _swv.addEventListener(ErrorEvent.ERROR, closeSWV); stage.addEventListener(Event.RESIZE, resizeSWV); _swv.stage = stage; resizeSWV(); var reqVars:URLVariables = new URLVariables(); reqVars.client_id = APP_ID; reqVars.response_type = 'code'; reqVars.redirect_uri = APP_URL; reqVars.state = getTimer(); reqVars.scope = 'www.googleapis/auth/userinfo.profile'; _swv.loadURL(AUTH_URL + reqVars); } private function closeSWV(event:Event=null):void { stage.removeEventListener(Event.RESIZE, resizeSWV); if (! _swv) return; _swv.removeEventListener(Event.COMPLETE, extractAccessToken); _swv.removeEventListener(LocationChangeEvent.LOCATION_CHANGE, extractAccessToken); _swv.removeEventListener(IOErrorEvent.IO_ERROR, closeSWV); _swv.removeEventListener(ErrorEvent.ERROR, closeSWV); _swv.dispose(); _swv = null; } private function resizeSWV(event:Event=null):void { if (! _swv) return; // align to the right-bottom corner _swv.viewPort = new Rectangle(stage.stageWidth - width, stage.stageHeight - height, width, height); } private function extractAccessToken(event:Event):void { trace('title: ' + _swv.title); trace('location: ' + _swv.location); var code:String = getValue('code=', _swv.title); if (code) { trace('code=' + code); closeSWV(); var reqVars:URLVariables = new URLVariables(); reqVars.code = code; reqVars.grant_type = 'authorization_code'; reqVars.client_id = APP_ID; reqVars.client_secret = APP_SECRET; reqVars.redirect_uri = APP_URL; var req:URLRequest = new URLRequest('accounts.google/o/oauth2/token'); req.method = URLRequestMethod.POST; req.data = reqVars; var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, handleComplete); loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleError); loader.addEventListener(IOErrorEvent.IO_ERROR, handleError); loader.load(req); } } private function handleError(event:ErrorEvent):void { var loader:URLLoader = URLLoader(event.target); trace(event.text); trace(loader.data); } private function handleComplete(event:Event):void { var obj:Object; var loader:URLLoader = URLLoader(event.target); trace(loader.data); try { obj = JSON.decode(loader.data); } catch(e:Error) { trace('Invalid JSON: ' + loader.data); return; } trace('access_token=' + obj.access_token); var req:URLRequest = new URLRequest('www.googleapis/oauth2/v1/userinfo?access_token=' + obj.access_token); var loader2:URLLoader = new URLLoader(); loader2.addEventListener(Event.COMPLETE, handleComplete2); loader2.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleError); loader2.addEventListener(IOErrorEvent.IO_ERROR, handleError); loader2.load(req); } private function handleComplete2(event:Event):void { var obj:Object; var loader:URLLoader = URLLoader(event.target); trace(loader.data); try { obj = JSON.decode(loader.data); } catch(e:Error) { trace('Invalid JSON: ' + loader.data); return; } var info:Object = { ID: obj.id, FIRST: obj.given_name, LAST: obj.family_name, FEMALE: (obj.gender != 'male'), AVATAR: obj.picture }; _userid.text = 'id: ' + info['ID']; _first.text = 'first: ' + info['FIRST']; _last.text = 'last: ' + info['LAST']; _female.text = 'female: ' + info['FEMALE']; _avatar.text = 'avatar: ' + info['AVATAR']; _img.source = info['AVATAR']; title = 'Your data'; _busy.visible = false; _busy.includeInLayout = false; _group.visible = true; } private function getValue(key:String, str:String):String { const pattern:RegExp = /[-_a-zA-Z0-9\/.]+/; var index:int = str.indexOf(key); if (index > -1) { var matches:Array = str.substring(index + key.length).match(pattern); if (matches.length > 0) return matches[0]; } return null; } ]]> </fx:Script> <s:BusyIndicator id="_busy"/> <s:VGroup id="_group" visible="false"> <s:Button id="_play" label="Start game"/> <s:Label id="_token"/> <s:Label id="_userid"/> <s:Label id="_first"/> <s:Label id="_last"/> <s:Label id="_female"/> <s:Label id="_avatar"/> <s:Image id="_img"/> </s:VGroup> </s:View>

更多推荐

如何在Flex移动应用程序中集成谷歌+

本文发布于:2023-11-23 16:07:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622073.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   如何在   Flex

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!