1. 準備
先去 google console
開啟 Google+ api service (Courtesy limit: 1,000 queries/day)
再來去 API Access create client ID and simple API Access
勾選 Application type and Redirect URI 填一填
Redirect URI:Google should redirect the browser after the user allows (or denies) the authorization request(簡單講就是授權完要導去的頁面)
2. API 流程
OAuth2->user 登入/同意取得權限->導回 redirect_url 並取得 access_token ->API Call
header ('Location: https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/plus.me&client_id=XXX@developer.gserviceaccount.com&redirect_uri=http://XXX/flash/jacky/google/&response_type=token');
scope:跟 user 取得的權限,目前 google 只開放
https://www.googleapis.com/auth/plus.me(Google+ You),
另外可以用+取得多個權限,像是
https://www.googleapis.com/auth/plus.me(Google+ You),
另外可以用+取得多個權限,像是
https://www.googleapis.com/auth/plus.me+https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/plus.people.recommended(Google+ Recommended People, Profile Information, You)
另兩個是隱藏 scope,雖然可以取得權限但無法執行對應的 API Call 。
html:將 access_token 傳給 swf
目前 google+ API 只提供 read 功能,而且最重要的圈圈功能都尚未公開
跟 FB 比還相當的陽春,期待之後進一步的改版囉。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html> | |
<head> | |
<title>GooglePlusDemo</title> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<meta name="language" content="en" /> | |
<meta name="description" content="" /> | |
<meta name="keywords" content="" /> | |
<script src="http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js" type="text/javascript"></script> | |
<script type="text/javascript"> | |
function getHashUrlVars(){ | |
var vars = [], hash; | |
var hashes = window.location.href.slice(window.location.href.indexOf('#') + 1).split('&'); | |
for(var i = 0; i < hashes.length; i++) | |
{ | |
hash = hashes[i].split('='); | |
vars.push(hash[0]); | |
vars[hash[0]] = hash[1]; | |
} | |
return vars; | |
} | |
</script> | |
<script type="text/javascript"> | |
var flashvars = { | |
token:getHashUrlVars()["access_token"] | |
}; | |
var params = { | |
quality: "high", | |
scale: "noscale", | |
wmode: "window", | |
allowscriptaccess: "always", | |
bgcolor: "#FFFFFF" | |
}; | |
var attributes = { | |
id: "flashContent", | |
name: "flashContent" | |
}; | |
swfobject.embedSWF("GooglePlusDemo.swf", "flashcontent", "800", "600", "10.0.0", "expressInstall.swf", flashvars, params, attributes); | |
</script> | |
</head> | |
<body> | |
<div id="flashcontent"> | |
<h1>GooglePlusDemo</h1> | |
<p>Alternative content</p> | |
<p><a href="http://www.adobe.com/go/getflashplayer"><img | |
src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" | |
alt="Get Adobe Flash player" /></a></p> | |
</div> | |
</body> | |
</html> |
目前 google+ API 只提供 read 功能,而且最重要的圈圈功能都尚未公開
跟 FB 比還相當的陽春,期待之後進一步的改版囉。
沒有留言:
張貼留言