您好,欢迎访问三七文档
当前位置:首页 > 金融/证券 > 金融资料 > FaceBook登陆充值接口文档Fro Java
FacebookAppsBasicIntegratewebapplicationswithcoreFacebookExperienceExample:gettinguserinformationandpostingtowallBenefit?Apowerfulandcosteffectivemeasuresforone'sproduct/servicetogainexposure(i.e.userengagement,viraleffect)GettingStartedStep1:RegisteringapplicationStep2:Setting-upapplicationStep3:AuthorizingapplicationStep4:AccessinguserinformationStep5:InteractingwithFacebookStep1:RegisteringApplicationAddFacebookdevelopapps@(Mobilephoneorcreditcard)Createyourapplication!GetauniqueapplicationIDandsecretHerewegosource::iFrameFBMLTinyscreensource::Scalabilityinthelongrun(i.e.easytomovetoFacebookConnectwebsite)LetyouuseJavascript,HTML,CSS(Ajaxanyone?)EasytodebugFBMLBenefits:EasytoaccessFacebookelementsFasterloadsNote:FBMLmightbedeprecatedStep2:Setting-upApplication-CanvasSetyourcanvasname(Veryimportant!)EasytorememberBrandingperspectiveExample::!!DevelopmentenvironmentassumptionJavaStruts2TomcatmySqlMosttutorialsandexamplesonthewebisinPHPStep3:AuthorizingapplicationIsitrequired?No!BUTitisnecessarytocreateapersonalizeduserexperience(i.e.retrieveuseremailaddress,posttowall)AppcreatorcontrolsthedegreeofpermissionsrequiredduringauthorizationTellmehow?CallthefollowingURIonyourdefaultindexpageuponload=YOUR_APP_ID&redirect_uri=YOUR_URLOr,appendspecificscopeparameters=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=email,read_streamAddthisapplicationsource:=text/javascript!--%Stringuri==12345678910;Stringperms=email,user_birthday;Stringurl==+perms+&client_id=+appId;Samplecode-Part2if(uri!=null){try{uri=java.net.URLEncoder.encode(uri,UTF-8);}catch(java.io.UnsupportedEncodingExceptione){}}url=url+&redirect_uri=+uri;out.println(varurl=\+url+\;);%if(url!=null){window.open(url,_parent,);}--/scriptWhat’snext?Havetoknowfact!Facebookpassesuserinformationintheformofsigned_requestparametertothecanvasURLThissigned_requestparameterisabase64urlencodedJSONobjectHuh?Simplysaying,signed_requesthastobedecodedtobemeaningful!SuperSecretsource::=null;StringsignedRequest=request.getParameter(signed_request);if(signedRequest==null||signedRequest.length()==0){log.error(AUTHERROR:Facebooksignedrequestismissing);returnERROR;}intcount=0;Stringpayload=null;Samplecode-Part2//BreakthecodeusingtokenizerStringTokenizerst=newStringTokenizer(signedRequest,.);while(st.hasMoreTokens()){if(count==1){payload=st.nextToken();break;}elsest.nextToken();count++;}Samplecode-Part3//DecodeBase64BASE64Decoderdecoder=newBASE64Decoder();//Replacespepayload=payload.replace(-,+).replace(_,/).trim();//DecodeBase64-payloadtry{byte[]decodedPayload=decoder.decodeBuffer(payload);payload=newString(decodedPayload,UTF8);}catch(IOExceptione){//TODOAuto-generatedcatchblocklog.error(ERROR:UnabletoperformBase64Decode);returnnull;}Samplecode-Part4//JSONDecode-payloadtry{JSONObjectpayloadObject=newJSONObject(payload);//ParseJSONdataaccessToken=+payloadObject.get(oauth_token);//Retrieveoauthtoken}catch(JSONExceptione){log.error(ERROR:UnabletoperformJSONdecode);}Step4:AccessinguserinformationThesimplicityofGraphAPIRESTstandard,returnsdatainJSONformatTrythefollowing://graph.facebook.com/me/pictureUtilizingaccesstokenMoststillreturnsinformationwithoutaccesstokenBUTDataislimitedtopublicinformationTrythefollowingwithaccesstoken=WHILESomestrictlyrequiresaccesstoken=TheJavaWayEasywaytoexecuteGraphAPIrequestGenericfunctionssupportedGettheAPIfrom=newDefaultFacebookClient(accessToken);JsonObjectfbUserJSON=facebookClient.fetchObject(me,JsonObject.class);StringfacebookId=fbUserJSON.getString(id);StringfirstName=fbUserJSON.getString(first_name);Step5:InteractingwithFacebookAccessingpopularFacebookfeaturesClient-sidescriptingusingJavascriptSDKExtensivefunctionalities:FrommakingGraphAPIcallstoopeningPopularDialogsPopularDial
本文标题:FaceBook登陆充值接口文档Fro Java
链接地址:https://www.777doc.com/doc-3923002 .html