dotnetopenauth的facebook登录获取好友头像

Facebook比较简单,基本上可以使用下载的DEMO。要注意的要点是:

1.权限设置:
FacebookClient中的AuthorizationEndpoint。具体设置示例如下:

AuthorizationEndpoint = new Uri("https://graph.facebook.com/oauth/authorize?scope=email,user_birthday,read_stream,publish_stream") 

2.要获得当前登录用户的EMAIL,需要进行权限设置以及电子邮件,然后可以通过以下方式获取用户的基本信息:

3.获取用户头像。 Facebook只需要知道用户的ID或名称即可获得它。通常,它是获得最大的尺寸,然后根据需要调整尺寸。地址如下:

http://graph.facebook.com/randy.ran.12327/picture?type=large //or http://graph.facebook.com/100000396765290/picture?type=large 

4.获取朋友列表,并检查朋友是否已使用此APP。要求地址:

https://graph.facebook.com/me/friends?fields=id,name,installed&limit=5000&offset=0 

请注意,默认情况下不返回已安装的参数。如果一个朋友已经使用过这个APP,那么这个 installed=true 基于此来确定哪些朋友使用了相同的APP。然后,您可以直接关注。

5.使用fbUI发送消息邀请朋友

<script src="http://connect.facebook.net/en_US/all.js"></script> <script type="text/javascript"> FB.init({ appId: 'app id', cookie: true, status: true, xfbml: true }); function FacebookInviteFriends2() { var link_url = "http://www.facebook.com/"; FB.ui({ method: 'send', to: '100001412299717', name: "Join me on my ibt!", description: "Randy is on Pinterest, a place to discover, collect, and share inspiration. Join Pinterest to see Randy's pins and start pinning.", picture: "http://media-cache-ec5.pinterest.com/avatars/randyran8_1356501711_444.jpg", link: link_url }, function (response) { alert(response); }); } </script> 

相关参考资料:https://developers.facebook.com/docs/reference/dialogs/requests/,以及此处的受邀朋友:http://www.9lessons.info/2012/07/facebook-invite-friends -api .html

6.通过API分享:

/// <summary> /// 分享到facebook /// </summary> /// <param name="token"></param> /// <param name="name">标题</param> /// <param name="link">点击了的连接地址</param> /// <param name="caption">caption(一行)</param> /// <param name="description">description</param> /// <param name="source">显示的图片地址150x150大小,需要以http开头的哦</param> /// <param name="message">评论内容</param> /// <returns></returns> public static BoolMessage Share(string token, string name, string link, string caption, string description, string source, string message) { Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("name", name); dic.Add("link", link); dic.Add("caption", caption); dic.Add("description", description); dic.Add("source", source); dic.Add("privacy", "{\"value\": \"EVERYONE\"}"); dic.Add("message", message); dic.Add("access_token",token); string url = "https://graph.facebook.com/me/feed"; return HttpHelper.WebRequest(HttpHelper.Method.POST, url,dic); } 


java下载facebook头像

1.获取用户头像。 Facebook只需要知道用户的ID或名称即可获得它。通常,它是获得最大的尺寸,然后根据需要调整尺寸。地址如下:

?
http://graph.facebook.com/randy.ran.12327/picture?type=large
//or
http://graph.facebook.com/100000396765290/picture?type=large
2.获取朋友列表,并检查朋友是否使用过此APP,请请求地址:

?
https://graph.facebook.com/me/friends?fields=id,name,installed&limit=5000&offset=0
3. API共享:
public static BoolMessage Share(string token, string name, string link, string caption, string description, string source, string message)
{
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("name", name);
dic.Add("link", link);
dic.Add("caption", caption);
dic.Add("description", description);
dic.Add("source", source);
dic.Add("privacy", "{\"value\": \"EVERYONE\"}");
dic.Add("message", message);
dic.Add("access_token",token);
string url = "https://graph.facebook.com/me/feed";
return HttpHelper.WebRequest(HttpHelper.Method.POST, url,dic);
}

因项目需求,网站需要在线获取facebook、twitter!等第三方平台用户的头像,整理了一个PHP方法:

 /** * 获取第三方平台头像 * @param $platformType string 平台种类 facebook/twitter */ public function getThirdPlatformAvatar($platformId, $!platformType = '') { if ($platformType == 'facebook') { $imgUrl = 'https://graph.facebook.com/' . $platformId . '/picture?type=large'; } else if ($platformType == 'twitter') { $im!gUrl = 'http://twitter.com/api/users/profile_image?id=' . $platformId; } $img = file_get_contents($imgUrl); $fileName = $platformId . time() .'.jpg'; $file = APP_PATH . 'data!/avatar/' . $fileName; file_put_contents($file, $img); $result = array( 'status' => 1, 'src' => DOMAIN . 'data/avatar/' . $fileName, 'id' => $platformId ); return $result; }

推荐阅读

tags

最新发布