Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CrocosにおけるFacebookアプリの開発と運用

 CrocosにおけるFacebookアプリの開発と運用

Facebook Night Vol.5 #fbnight にて発表したスライドです。

Sotaro Karasawa

April 24, 2012
Tweet

More Decks by Sotaro Karasawa

Other Decks in Technology

Transcript

  1. CrocosϚʔέςΟϯά ݒ৆ 2011/7 ϦϦʔε ྦྷܭ 67ສ Ԡื ྦྷܭ։࠵ 2,000 ݅

    ಉ࣌։࠵ 350 ݅ Install 72,000 MAU 40,000~65,000 http://marketing.crocos.jp/
  2. ؀ڥ Apache 2.2 PHP 5.3 Symfony2 CrocosFrameworkBundle Facebook - PHP

    SDK - JS SDK Amazon Web Service ELB + EC2, RDS
  3. ؀ڥ Apache 2.2 PHP 5.3 Symfony2 CrocosFrameworkBundle Facebook - PHP

    SDK - JS SDK Amazon Web Service ELB + EC2, RDS Facebookͱͷͭͳ͗ࠐΈ
  4. FacebookΞϓϦͷઃఆ ࣗ෼ͷ։ൃ༻ Staging༻ Production༻ appId: 11111111 secret: xxxxxxxxx sandbox: on

    appId: 2222222 secret: YYYYYYYY sandbox: on appId: 33333333 secret: ZZZZZZZZ sandbox: off
  5. FacebookΞϓϦͷઃఆ ࣗ෼ͷ։ൃ༻ Staging༻ Production༻ appId: 11111111 secret: xxxxxxxxx sandbox: on

    appId: 2222222 secret: YYYYYYYY sandbox: on appId: 33333333 secret: ZZZZZZZZ sandbox: off ࣗ෼ͷ։ൃ͸ࣗ෼ͷ։ൃ༻ΞϓϦͰ
  6. FacebookΞϓϦͷઃఆ ࣗ෼ͷ։ൃ༻ Staging༻ Production༻ appId: 11111111 secret: xxxxxxxxx sandbox: on

    appId: 2222222 secret: YYYYYYYY sandbox: on appId: 33333333 secret: ZZZZZZZZ sandbox: off ϦϦʔεલͷςετ͸εςʔδϯά؀ڥ
  7. FacebookΞϓϦͷઃఆ ࣗ෼ͷ։ൃ༻ Staging༻ Production༻ appId: 11111111 secret: xxxxxxxxx sandbox: on

    appId: 2222222 secret: YYYYYYYY sandbox: on appId: 33333333 secret: ZZZZZZZZ sandbox: off ϦϦʔεޙӡ༻͢Δຊ൪༻ΞϓϦ
  8. FacebookΞϓϦͷઃఆ Symfony2 - config Λ Environment Ͱ෼͚Δ - ex. config.prod.yml

    / config.dev.yml - parameter ؔ࿈ΛσϓϩΠͰ෼͚Δ - $ cap staging deploy → parameters.ini-staging
  9. Facebook PHP SDK Λ wrap ͨ͠ Service 1. API ͷ

    RequestɺResponse ͷ Trace 2. JSON ʹؚ·ΕΔ Facebook ID ͷमਖ਼ 3. Access Token ͷνΣοΫ 4. ֤छAPI͝ͱͷ֦ுΠϯλʔϑΣΠε
  10. API ͷ RequestɺResponse ͷ Trace ϩάܗࣜͰऔಘ ɾRequest URIɺύϥϝʔλ ɾੜͷ JSON

    Response ɾResponse Time ຊ൪: Τϥʔൃੜ࣌ͷAccessTokenɺϦΫΤετΛ͙͢ ʹ೺ѲͰ͖Δ
  11. API ͷ RequestɺResponse ͷ Trace [2012-04-21 11:37:03] request.INFO: Matched route

    "present_facebook_show" (parameters: "_controller": "Crocos\PresentBundle\Controller\Facebook\PresentController::showAction", "id": "13034", "_route": "present_facebook_show") [] [] [2012-04-21 11:37:03] app.DEBUG: Facebook API[1]: https://graph.facebook.com/oauth/ access_token - {"client_id":"11111","client_secret":"xxxxx","redirect_uri":"","code":"2.AQBVWlPrgM3KmxDP. 3600.1334980800.5-100003311356353|zzzzz"} (11111|xxxxx) [] [] [2012-04-21 11:37:03] app.DEBUG: Facebook API[2]: https://graph.facebook.com/? ids=115014768608225 - {"method":"GET"} (xxxxxaccess_tokenxxxxx) [] [] [2012-04-21 11:37:04] app.DEBUG: Facebook API[2] result: {"115014768608225": {"id":"11111","name":"\u30af\u30e9\u30d6","picture":"http:,,,.jpg","link":"http:\/\/ www.facebook.com\/kamekameclub","likes":589,"cover":{"cover_id": 199653950144306,"source":"http:,,.jpg","offset_y":0},"category":"Internet\/ software","is_published":true,"has_added_app":true,"username":"kamekameclub", ...,"latitude": 35.199837218473,"longitude":136.99680292309},"can_post":true,"checkins": 1,"talking_about_count":96}} [] [] [2012-04-21 11:37:04] app.DEBUG: Fetched pages expected(11111), actual(11111) [] [] [2012-04-21 11:37:04] app.DEBUG: Facebook API[3]: https://graph.facebook.com/12344/likes/ 23456 - {"method":"GET"} (xxxxxaccess_tokenxxxxx) [] [] [2012-04-21 11:37:05] app.WARNING: Facebook API[3] error: OAuthException: Error validating application. Invalid application ID. [] [] [2012-04-21 11:37:05] app.WARNING: Caught a FacebookApiException: OAuthException: Error validating application. Invalid application ID. [] [] [2012-04-21 11:37:05] request.CRITICAL: FacebookApiException: Error validating application. Invalid application ID. (uncaught exception) at vendor/facebook/src/base_facebook.php line 1040 [] []
  12. JSON ʹؚ·ΕΔ Facebook ID ͷमਖ਼ ɾFacebook ͷ ID ͕Ͱ͔͗ͯ͢ 32bit

    ؀ڥ ͰյΕΔ ɾੲAWSͷখ͍͞ͷ͸64bit൛͕ͳ͔ͬͨ ɾJSON ͷͰ͔͍ Integer Λ String ʹม׵ ʢPHP >= 5.4: JSON_BIGINT_AS_STRING ) {id: 123456789012, ...} → {id:"123456789012", ...}
  13. JSON ʹؚ·ΕΔ Facebook ID ͷमਖ਼ protected function fixjson($json) { $pattern

    = '/(":)(\d+)([,\}])/'; return preg_replace_callback($pattern, function($matches) { return $matches[1] ɹɹɹɹɹɹɹɹ. '"'.$matches[2].'"' ɹɹɹɹɹɹɹɹ. $matches[3]; }, $json); }
  14. Access Token ͷνΣοΫ Access Token ɾApplication Access Token ɾUser Access

    Token ɾPage Access Token /me → User Access Token ͕ඞཁ
  15. ࠷ऴ๷ӴϥΠϯ Uncaught Exception Ͱ Fatal ͸ਏ͍ ๷͗Α͏ͷͳ͍໰୊ͨͪ: ɾSSL read: error

    00000000:lib(0):func(0).. errno 104 ɾEmpty reply from server ɾOperation timed out after 60001 milliseconds ɾAn unexpected error has occurred. Please retry your request later ʮ͍ͨͩ·Facebookʹ໰୊͕ੜ͓ͯ͡Γ·͢ʯ
  16. ϦΫΤετͷ Cache (୤ઢ) Cache ૢ࡞ͷྫ: ɾFacebook Page ͷ৘ใΛ·ͱΊͯऔಘ ɹ→ 1111,

    2222, 3333 ɾAPI: /?ids=1111,2222,3333 $facebook->getPageInfo([1111, 2222, 3333]); Cache ʹ৐ͬͯͳ͍ ID ͚ͩϦΫΤετΛ౤͛Δ
  17. Facebook ΞϓϦͷ։ൃ (·ͱΊ) ɾṖͷϊ΢ϋ΢ (BK) ɾ࢓༷೺Ѳ (Exception ͷ಺༰ɾڍಈ) ɾSDK ͷڍಈ೺Ѳ

    ɹɾඞཁ͕͋Ε͹मਖ਼ɺόάϨϙʔτ ɹɾPHP SDK ಡΈ΍͍͢ ɾ→ ͦΕͳΓʹେม ɾ→ ৘ใڞ༗͍͖ͯ͠·͠ΐ͏
  18. ϖʔδ৘ใ͕औಘͰ͖ͳ͍ 3. ࢓༷೺Ѳ ɾException ͕ग़ͳ͍Ͱ false ɾGraph API Explorer Ͱ֬ೝ

    ɹɾࣗ෼ͷAccess Token / ΞϓϦAccess Token ɹɾࣗ෼ͷϖʔδ / ଞͷਓͷϖʔδ ɹ㱺 جຊతʹσʔλ͸ฦͬͯ͘Δ ɹ㱺 ΞϓϦͷAccess TokenͰ΋ެ։৘ใ͸ͱΕ ɹɹΔ
  19. ϖʔδ৘ใ͕औಘͰ͖ͳ͍ 3. ࢓༷೺Ѳ ɾis_published ɹGraph API ͷ݁Ռʹؚ·Ε͍ͯΔ ɹͨͩ͠ɺ͜Ε͕ false ͷϖʔδͰ৘ใ͕औಘͰ͖

    Δͷ͸ɺͦ΋ͦ΋ͦͷϖʔδͷ؅ཧऀͷAccess TokenΛ࢖͍ͬͯΔ৔߹ ɹʢߟ͑ͯΈΕ͹ɺ౰ͨΓલʣ
  20. ͦͷଞ࣮ࡍʹ͋ͬͨ࿩ ɾ all.js ಡΊͳ͍ ... ɹ㱺 connect.facebook.net DNS ো֐ ɾFacebookApiException:

    (#21) Page ID xxxx was migrated to page ID yyyy. Please update your API calls to the new ID ɹ㱺 Facebookϖʔδ͕εϙοτొ࿥͢Δͱ ϖʔδID͕มΘΔ
  21. ৘ใͷ࢓ೖΕํ (2) Bugs / Platform Status Bugs http://developers.facebook.com/bugs Platform Status

    http://developers.facebook.com/live_status 㱺 Crocos Ͱ͸ɺ͜ͷ಺༰Λ IRC ʹ௨஌
  22. ৘ใͷ࢓ೖΕํ (4) Facebookϖʔδ/Facebookάϧʔϓ Facebook Marketing Solutions Japan http://www.facebook.com/marketingjapan Facebook API

    Developers JAPAN http://www.facebook.com/groups/350715528292106/ Facebook Mobile Hack - Tokyo http://www.facebook.com/groups/243729729057503/