Facebook.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /******************************************************************************
  2. Please read following instructions carefully in order to know how to enable Facebook support.
  3. In order to use 'Facebook' class, you need to:
  4. 1. Create a "Facebook App" on https://developers.facebook.com/apps/ with exact same name as your Esenthel Application
  5. 1. Click on the App
  6. 2. Select "Settings" tab on the left side
  7. 3. Click "Add Platform"
  8. 4. Select "Android" and "iOS"
  9. 5. Set "Package Name" (Android) and "Budle ID" (iOS) to be the same as your Esenthel Application (this can be viewed by double-clicking on Application in Esenthel Editor)
  10. 6. Enable "Single Sign On" option for both platforms
  11. 7. For "iOS Platform" set "iPhone/iPad Store ID" to your App "Apple ID" (this can be viewed from https://itunesconnect.apple.com/ "Manage Your Apps\Your App\App Information\Identifiers\Apple ID")
  12. 8. For "Android Platform" set "Key Hashes" from:
  13. 1. In Esenthel Editor, open Editor options "M\Editor Options"
  14. 2. Go to "Certificates" tab
  15. 3. Click on "Get Android Key Hash for Facebook"
  16. 4. Paste that Key Hash to the "Key Hashes" field on the Facebook App Settings page
  17. 9. Click "Save Changes" on the bottom of the Facebook App page
  18. 2. Set your Facebook App ID, obtained from https://developers.facebook.com/apps/ to Esenthel Application properties (by double-clicking on Application in Esenthel Editor)
  19. 3. For Android you need to compile your app in "Release" mode (for iOS it doesn't matter), as only "Release" apps are signed with your certificate, which hash we've set on the Facebook page
  20. 4. Once you will be releasing your application to public, you also need to make your "Facebook App" available to the public on the https://developers.facebook.com/apps/ website under the "Status & Review" - field "Do you want to make this app and all its live features available to the general public?"
  21. /******************************************************************************/
  22. #define FACEBOOK (ANDROID || IOS) // if Facebook is supported on this platform
  23. /******************************************************************************/
  24. struct Facebook
  25. {
  26. struct User
  27. {
  28. ULong id ; // user id
  29. Str name; // user name (first+last)
  30. void clear() {id=0; name.clear();}
  31. };
  32. struct UserEmail : User
  33. {
  34. Str email; // user email
  35. void clear() {User::clear(); email.clear();}
  36. };
  37. #if EE_PRIVATE
  38. // !! these enums must be equal to "EsenthelActivity.java" !!
  39. #endif
  40. enum RESULT
  41. {
  42. POST_ERROR , // there was an error while trying to post
  43. POST_CANCEL , // user canceled posting
  44. POST_SUCCESS , // post completed successfully
  45. POST_NOT_LOGGED_IN, // user is not logged in to Facebook, and the result of the post is unknown
  46. };
  47. void (*callback)(RESULT result); // pointer to a custom function that will be called with processed events, 'result'=message received at the moment
  48. // manage
  49. Bool loggedIn()C; // if currently logged in to Facebook
  50. Facebook& logIn () ; // log in to Facebook
  51. Facebook& logOut () ; // log out from Facebook
  52. Facebook& getMe (); // request my profile information to be downloaded, 'logIn' will be automatically called if needed
  53. Facebook& getFriends(); // request my friends profile information to be downloaded, 'logIn' will be automatically called if needed
  54. C UserEmail & me ()C {return _me ;} // get my profile information, 'getMe' should be called first
  55. C Mems<User>& friends()C {return _friends;} // get my friends profile information, 'getFriends' should be called first
  56. Str userImageURL(ULong user_id, Int width=-1, Int height=-1)C; // get user image url from which you can download his/her photo, for example by using the 'Download' class, 'width height'=custom dimensions of the image in pixels -1..Inf (-1=default), you can leave both as default, or specify only one and the other will be set automatically, or you can specify both dimensions, they are treated as hints only
  57. // operations
  58. void openPage(C Str &page_name, C Str &page_id=S); // open a Facebook page, 'page_name'=name of the page (for example "EsenthelEngine"), 'page_id'=ID number of the page (for example "161038147263508", this is optional). By default the page will be opened in a browser, however on Android and iOS, if you specify the 'page_id', then it will be opened in the Facebook app if it's available.
  59. void post(C Str &message, C Str &url=S, C Str &image_url=S, C Str &title=S, C Str &desc=S, C Str &caption=S); // post message to user's timeline, 'message'=message to post (if left as empty then a dialog will be opened where the user will be able to set his own message, this parameter is currently ignored and the dialog is always opened), most of the parameters are optional (if left empty, then Facebook will set them to default values), 'logIn' will be automatically called if needed
  60. #if !EE_PRIVATE
  61. private:
  62. #endif
  63. UserEmail _me;
  64. Mems<User > _friends;
  65. Facebook();
  66. }extern
  67. FB;
  68. /******************************************************************************/