我正在将facebook登录集成到我的应用程序中,evrything工作正常。我现在想要两件事。
我希望每当有新用户点击并点击“使用facebook登录”时,在所有流程之后,应该在该用户墙上发布帖子,该用户已开始使用我的应用程序并带有指向app的链接.. 就像我们看到那些游戏一样,“< user>开始使用Hold'em扑克”
获取用户个人资料图片
此处是指向http://oauth.netne.net/index.php
的链接我怎样才能做到这一点?
答案 0 :(得分:1)
使用Javascript:
function doPost() {
var params = {};
params['message'] = "<USER> started using <YOUR APP NAME>";
params['name'] = '<YOUR APP NAME>';
params['description'] = '<DESCRIPTION ABOUT YOUR APP>';
params['link'] = "<LINK TO YOUR WEBSITE>";
//ON CLICKING THE POST WHERE YOU WANT USER TO BE REDIRECTED e.g. www.yoursite.com
params['picture'] = '<PATH OF PICTURE THAT YOU WANT TO BE DISPLAYED ON THE POST>';
FB.api('/me/feed', 'post', params, function(response) {
if(!response || response.error) {
console.log('ERROR OCCURED '+response.error);
}
else {
console.log('POSTED SUCCESSFULLY');
}
}}
使用PHP:
$ret_obj = $facebook->api('/me/feed', 'POST',
array( 'link' => '<LINK TO YOUR WEBSITE>',
'message' => '<USER> started using <YOUR APP NAME>',
'description' => "<DESCRIPTION ABOUT YOUR APP>")); //Returns the POST ID.
$fbImageUrl = https://graph.facebook.com/**<FBUSER_ID>**/picture?type=<VALUE>
(或)
$fbImageUrl = https://graph.facebook.com/**<FBUSER_NAME>**/picture?type=<VALUE>
哪里可以是“小”或“正常”或“大”或“正方形”。
//用于保存图片:
$localFilePath = 'pathToImagesFolder/<SOME_NAME>.jpg'; //Use relative path.
$fbImage = file_get_contents($fbImageUrl); //Fetches the image and stores it in variable.
file_put_contents($file1, $img1); //Will save the image in the path specified.
答案 1 :(得分:0)
try {
$ret_obj = $facebook->api('/me/feed', 'POST',
array( 'link' => '<LINK TO YOUR WEBSITE>',
'message' => '<USER> started using <YOUR APP NAME>',
'description' => "<DESCRIPTION ABOUT YOUR APP>"));
} catch(FacebookApiException $e) {
$login_url = $facebook->getLoginUrl(array('scope' => 'publish_stream'));
header("Location: $login_url");
}
但如果用户连续重定向,这会使用户烦恼。因此,最好跳过这一步而不是强迫用户接受它。请记住,您应该提供注册时所需的所有范围。