我正在尝试将Google Friend Connect作为登录解决方案。我使用PHP客户端实现了Facebook Connect,并且我想使用OpenSocial PHP客户端库(OpenSocial)对Google Friend Connect(http://code.google.com/p/opensocial-php-client/)使用相同的方法。用户连接后,我想获取他们的OpenSocial ID并将其登录到数据库中。
到目前为止,这是代码:
$gfc_provider = new osapiFriendConnectProvider();
$gfc_auth = new osapiOAuth2Legged(GFCAPIKEY, GFCSECRET);
$gfc_osapi = new osapi($gfc_provider, $gfc_auth);
$batch = $gfc_osapi->newBatch();
$batch->add($gfc_osapi->people->get(array('userId' => '@me')));
$result = $batch->execute();
print_r($result);
以下是回复:
Array (
[0] => osapiError Object (
[errorCode:private] => 400
[errorMessage:private] =>
Cannot ask for me when anonymous
Error 400
[response] =>
)
)
我不确定我做错了什么。有什么建议吗?
答案 0 :(得分:3)
对于那些希望以与使用Facebook Connect相同的方式使用Google朋友群的人来说,我就是这样做的(在Arne的帮助下)。我已经加入了Facebook Connect比较:
Facebook(PHP):
$facebook = new Facebook(FBAPIKEY, FBSECRET);
$facebook_id = $facebook->get_loggedin_user();
Google Friend Connect(PHP):
if ($_COOKIE["fcauth" . GFCSITEID] != ''){
$gfc_provider = new osapiFriendConnectProvider();
$gfc_auth = new osapiFCAuth($_COOKIE["fcauth" . GFCSITEID]);
$gfc_osapi = new osapi($gfc_provider, $gfc_auth);
$batch = $gfc_osapi->newBatch();
$batch->add($gfc_osapi->people->get(array('userId' => '@me')));
$result = $batch->execute();
$opensocial_id = $result[0]['data']->id;
}
(请注意,您需要Arne从上面的链接提供的更新文件,以使用osapiFCAuth对象)
Facebook(JavaScript):
FB.init("XXXXXXXXXXXXXXXXXXXXXXX", "xd_receiver.htm", {"reloadIfSessionStateChanged":true});
Google Friend Connect(JavaScript):
google.friendconnect.container.setParentUrl('/');
google.friendconnect.container.initOpenSocialApi({
site: 'XXXXXXXXXXXXXXXXXXXXX',
onload: function(securityToken) {
var req = opensocial.newDataRequest();
req.add(req.newFetchPersonRequest('VIEWER'), "viewer");
req.send(function(response) {
var data = response.get('viewer').getData();
if (data){
var opensocial_id = data.getId();
if (opensocial_id && $("div#gfc").length > 0) window.location.reload();
}
});
}
});
if ($('div#gfc').length > 0) google.friendconnect.renderSignInButton({'id':'gfc', 'text':'Connect with Google', 'style':'long'});
Facebook(HTML):
<fb:login-button size="medium" length="long"></fb:login-button>
Google Friend Connect(HTML):
<div id="gfc"></div>
答案 1 :(得分:0)
仅供参考,讨论已移至opensocial-client-libraries Google Group(http://groups.google.com/group/opensocial-client-libraries/browse_thread/thread/9976bf92a13be775)