C#で作成するfacebookアプリ mvp community camp

  • Published on
    28-May-2015

  • View
    2.488

  • Download
    7

Embed Size (px)

Transcript

  • 1. 2014.03.22 CLR/H #89 (MVP Community Camp 2014) FacebookWebC# C#Facebook

2. Twitter @furuya02 BlackJumboDog CLR/H Microsoft MVP for Visual C# (2013/1) 3. Facebook FacebookSDK Graph API FQL OAuth Facebook 4. Facebook http://mvpcamp.azurewebsites.net/ 5. FacebookSDK Facebook facebook.com iOSAndroid OS SDK WebFacebook 6. SDK PHP(SDK) 7. JavaScript facebook _Layout.cshtml View 8. Facebook SDK for .NET FacebookClient 9. Facebook SDK for .NET Install-Package Facebook PM> Install-Package Facebook 'Facebook 6.0.18' 'Facebook 6.0.18' 'Facebook 6.0.18' SampleApp 'Facebook 6.0.18' SampleApp 10. (1) Register Now (2) Facebook http://www.slideshare.net/furuya02/facebook-26186324 11. Graph API Facebook http://graph.facebook.com/ URLGetJSON 12. WebRequest ()MiscrosoftHTTPGET 13. PHP-SDK $facebook->api(url) SDK http://graph.facebook.com/ Get Facebook 14. C#SDK Get() Facebook http://graph.facebook.com/ Get SDK 15. GraphAPI graph.facebook.comWebAPI http://graph.facebook.com/ 16. OpenGraph nodes (such as a User, a Photo, a Page, a Comment), edges (such as a Page's Photos, or a Photo's Comments), fields (such as the birthday of a User, or the name of a Page). Quickstart for Graph API https://developers.facebook.com/docs/graph-api/quickstart/ 17. (node) ID etc. URL http://graph.facebook.com/Microsoft A 14 Micro soft ~~ 18. (node) GETGet() http://graph.facebook.com/Microsoft (PHP) #result = $facebook->api('/Microsoft'); var result = client.Get(Microsoft); http://facebooksdk.net/docs/making-synchronous-requests/#0 19. (node) id()username() { "category": "Company", "username": "Microsoft", "website": "http://www.facebook.com/Microsoft", "id": "20528438720", "link": "http://www.facebook.com/Microsoft", "likes": 4002578, http://graph.facebook.com/Microsoft http://graph.facebook.com/20528438720 username id 20. (Edge) Like etc. URL http://graph.facebook.com/Microsoft/feed Micro soft 13 15 11 21. http://graph.facebook.com/Microsoft/feed (PHP) #result = $facebook->api('/Microsoft/feed'); (Edge) GETGet() var result = client.Get(/Microsoft/feed); http://facebooksdk.net/docs/making-synchronous-requests/#0 22. (field) idetc. http://graph.facebook.com/Microsoft?fields=id,name Id: 20528438720 name: Microsoft website: http://www..... likes: 4036786 23. http://graph.facebook.com/Microsoft?fields=id,name (PHP) #result = $facebook->api('/Microsoft','GET ,array('fields' => 'name,id')); (field) Get() var result = client.Get(Microsoft,new{ fields = "name,id" }); http://facebooksdk.net/docs/making-synchronous-requests/#0 24. (PHP) #result = $facebook->api('/Microsoft?fields=name,id'); //2 var result = client.Get(Microsoft , new{ fields = name,id }); //1 var result = client.Get(Microsoft?fields=name,id); 25. (access_token=) 26. FacebookClientAccessToken namespace Facebook { // Provides access to the Facbook Platform. public class FacebookClient { public FacebookClient(); public FacebookClient(string accessToken); // Gets or sets the access token. public virtual string AccessToken { get; set; } // Gets or sets the app id. public virtual string AppId { get; set; } // Gets or sets the app secret. public virtual string AppSecret { get; set; } public virtual Func SerializeJson { get; set; } 27. AccessToken http://graph.facebook.com/?access_token=CACACACA public class FacebookClient { public virtual string AccessToken { get; set; } 28. 1 AccessToken 2 3 C#SDK var client = new FacebookClient(){ }; client.AccessToken = CACACA"; new FacebookClient(CACACA){ }; client.Get("Microsoft/feed?access_token=CACACA"); client.Get("Microsoft/feed,new{access_token=CACACA}); 29. GrapgAPI GET http://graph.facebook.com/Microsoft/feed?fields=name,id&access_tokrn=CACACA var client = new FacebookClient(accessToken); var result = client.Get(Microsoft/feed , new{ fields = name,id }); 30. GETGraphAPI client.Post(me/feed,new {message=); client.Post(ID,new {message="}); client.Delete("ID"); 31. graph.facebook.com/search?q={your-query}&[type={object-type}] client.Get(search , new{ q = ,type=post }); https://developers.facebook.com/docs/graph-api/using-graph-api 32. GET var result = client.Batch( new FacebookBatchParameter("me"), new FacebookBatchParameter("me/feed) ); http://facebooksdk.net/docs/making-synchronous-requests/#4 33. FQL Facebook SQLGraph API SELECT [fields] FROM [table] WHERE [conditions] 34. FQL GraphAPI https://api.facebook.com/method/fql.query ?query=QUERY http://graph.facebook.com /fql?q=QUERY 35. FQL Get() http://graph.facebook.com/fql?q=QUERY (PHP) #result = $facebook->api(array( 'method' => 'fql.query', 'query' => QUERY )); var result = client.Get(fql,new{q=QUERY}); http://facebooksdk.net/docs/making-synchronous-requests/#3 36. FQL https://developers.facebook.com/docs/reference/fql 37. FQL https://developers.facebook.com/docs/reference/fql/user/ 38. FQL SELECT uid,name,sex,pic,username FROM user WHERE username ="taro SELECT pic FROM user WHERE uid=xxxxxxxxxxxx URL SELECT url FROM object_url WHERE url AND id IN (SELECT object_id FROM like WHERE user_id=me()) SELETE * WHERE(1=1) 39. FQL (PHP) $results = $facebook->api(array( 'method' => 'fql.multiquery', 'queries' => array( 'query1' => 'SELECT ', 'query2' => 'SELECT ...', ), )); http://facebooksdk.net/docs/making-synchronous-requests/#3 var result = client.Get("fql", new{ q = new[]{ "SELECT uid from user where uid=me()", "SELECT name FROM user WHERE uid=me()" } }); 40. AOuth 41. WebOAuth /www.facebook.com/dialog/oauth?redirect_url=callBack public ActionResult callBack(string code) /graph.facebook.com/oauth/access_token?code=xxx www.facebook.com 42. dialog/oauth C#SDK var url = client.GetLoginUrl(new { client_id = XXXX, // client_secret = XXXXXXXXX, redirect_uri = "http://localhost/Home/CallBack", // //scope = email }); return Redirect(url.AbsoluteUri); "https://www.facebook.com/dialog/oauth? client_id=XXX& client_secret=XXXXXX& redirect_uri=http://localhost/Home/Callback 43. code C#SDK public ActionResult CallBack(string code,string error){ if(error!=null){ // View(ERROR); }; //code } 44. access_token C#SDK var client = new FacebookClient(){}; dynamic result = client.Get("oauth/access_token", new{ client_id = XXX, // client_secret = XXXXXXX,// redirect_uri = "http://localhost/Home/CallBack", // code = code // }); var accessToken= result.access_token; oauth/dialog http://graph.facebook.com/oauth/access_token? 45. Facebook (T^T) 46. 1 2 URL 47. FQLlike like SELECT object_id FROM like WHERE user_id=me() Like object_id object_idURL https://www.facebook.com/object_id https://developers.facebook.com/docs/reference/fql/like/ 48. FQLlikeobject_id { "data": [ { "object_id": "6673XXX0002813" }, { "object_id": "7532XXX8023129" }, { "object_id": "2262XXX0897216" }, { "object_id": "7061XXX6107744" var result = client.Get(fql,new { q= SELECT object_id FROM like WHERE user_id=me()}); 49. object_id() var result = client.Get(object_id); { "id": "75322XXXXX3129", "created_time": "2014-03-20T13:22:49+0000", "from": { "name": YAMADA TARO, "id": "100000XXXXXXXX" }, message: ******** link: https://www.facebook.com/photo.php? ******** ", "updated_time": "2014-03-20T13:22:49+0000", "comments": { } likes{ } 50. Batch var list = new List(); foreach (var d in data){ list.Add(new FacebookBatchParameter(d.object_id)); } var result = client.Batch(list.GetRange((n*50),50).ToArray()); 78/50 Batch 2.3/50 SQL 150Batch 51. Facebook 1 2 3 52. GraphAPIsearch type=post 25 limit=100 var result = client.Get(search?type=post&q={}&limit=100"); { "data": [ { "id": "100000466595635_854462207912658", "from": { "name": "Masayuki Shake Matsushita", "id": "100000466595635" }, "story": "Masayuki Shake Matsushita shared Yuzo Fabio Iwata's event.", "link": "https://www.facebook.com/events/667356079989254/", "actions": [ { "name": "Like", "link": "https://www.facebook.com/100000466595635/posts/854462207912658" } ], "privacy": { "value": "" }, "type": "link", "application": { "name": "Links", "id": "2309869772" }, "created_time": "2014-03-21T01:07:24+0000", 53. 1 2 3 4 54. me post likesid likes25 limit var q=me/posts?fields=type,message,story,picture,link,created_time, likes.limit(500).fields(id)&limit=300"; var result = client.Get(q); { "data": [ { "type": "photo", "message": "3/22 n "picture": "https://fbcdn-photos-g-a.akamaihd.net/hphotos-ak-ash3/t1.0-0/537110_6216632012 "link": "https://www.facebook.com/photo.php?fbid=621663201243765&set=a.200848559991900 "created_time": "2014-03-20T06:04:11+0000", "id": "100002002711624_621663487910403", "likes": { "data": [ { "id": "10000XXXXXXX426" }, { "id": "10000XXXXXXX951" }, { "id": "10000XXXXXXX367" }, { "id": "10000XXXXXXX377" 55. http://www.sapporoworks.ne.jp/spw http://www.irasutoya.com/