Hive provides users a function to sync with Facebook account. By using Hive API, therefore, you can search user profile and friend lists on Facebook, help users send messages to Facebook friends, and help them post on Facebook News Feed.
Facebook functions are available when user signs in Facebook. If a user not signed in Facebook tries to use the Facebook functions, Hive Client displays a login page to sign in Facebook.
Facebook Profile
To search user’s Facebook profile data, implement getMyProfile()
method in the SocialFacebook class. The data is returned as a part of ProfileFacebook list.
API Reference: hive.SocialFacebook.getMyProfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// Callback handler managing the result of getting Facebook profile data. public void onProfileFacebookCB(ResultAPI result, List<ProfileFacebook> profileList) { if(result.isSuccess() && profileList != null){ foreach (ProfileFacebook profile in profileList) { // Check the Facebook profile data. } } } // Search the Facebook profile data. hive.SocialFacebook.getMyProfile(onProfileFacebookCB); |
API Reference: SocialFacebook::getMyProfile
1 2 3 4 5 6 7 8 9 10 |
// Search the Facebook profile data. SocialFacebook::getMyProfile([=](ResultAPI result, std::vector<ProfileFacebook> profileList){ // Callback function managing the result of getting Facebook profile data. if(result.isSuccess() && profileList != nullptr) { for(ProfileFacebook profile : profileList){ // Check the Facebook profile data. } } }); |
API Reference: com.hive.SocialFacebook.getMyProfile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
// Search the Facebook profile data. SocialFacebook.getMyProfile(new SocialFacebook.ProfileListener() { @Override public void onProfile(ResultAPI result, List<ProfileFacebook> profileList) { // Callback listener managing the result of getting Facebook profile data. if( result.isSuccess() && profileList != null){ for (ProfileFacebook profileFacebook : profileList) { // Check the Facebook profile data. } } } }); |
API Reference: HIVESocialFacebook:getMyProfile
1 2 3 4 5 6 7 8 9 10 |
// Search the Facebook profile data. [HIVESocialFacebook getMyProfile:^(HIVEResultAPI *result, NSArray<HIVEProfileFacebook *> *profileList) { // Callback handler managing the result of getting Facebook profile data. if( [result isSuccess] && profileList != nil) { for (HIVEProfileFacebook *profileFacebook in profileList) { // Check the Facebook profile data. } } }]; |
Searching Friends List on Facebook
Implement getFriends()
method in the SocialFacebook class to search the list of user’s Facebook friends.
Followings are sample codes to search the friends list on Facebook.
API Reference: hive.SocialFacebook.getFriends
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// Callback handler managing the result of searching friends list on Facebook. public void onFriendsFacebookCB(ResultAPI result, List<ProfileFacebook> profileList) { if(result.isSuccess()){ foreach(ProfileFacebook profile in profileList) { // Check the friends list on Facebook.. } } } // Search the friends list on Facebook. hive.SocialFacebook.getFriends(onFriendsFacebookCB); |
API Reference: SocialFacebook::getFriends
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
// Search the friends list on Facebook. SocialFacebook::getFriends([=](ResultAPI result, std::vector<ProfileFacebook> profileList){ // Callback function managing the result of searching friends list on Facebook. if(result.isSuccess() && profileList != nullptr) { for(ProfileFacebook profile : profileList) { // Check the friends list on Facebook.. } } }); |
API Reference: com.hive.SocialFacebook.getFriends
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// Search the friends list on Facebook. SocialFacebook.getFriends(new SocialFacebook.ProfileListener() { @Override public void onProfile(ResultAPI result, List<ProfileFacebook> profileList) { // Callback listener managing the result of searching friends list on Facebook. if(result.isSuccess() && profileList != null){ for (ProfileFacebook profile : profileList) { // Check the friends list on Facebook.. } } } }); |
API Reference: HIVESocialFacebook:getFriends
1 2 3 4 5 6 7 8 9 10 |
// Search the friends list on Facebook. [HIVESocialFacebook getFriends:^(HIVEResultAPI *result, NSArray<HIVEProfileFacebook *> *profileList) { // Callback handler managing the result of searching friends list on Facebook. if([result isSuccess] && profileList != nil) { for (HIVEProfileFacebook *profileFacebook in profileList) { // Check the friends list on Facebook.. } } }]; |
Inviting Facebook Friends
Users synced Hive with Facebook account can invite Facebook friends to the game that a user currently plays. To display invitation page, implement showInvitationDialog()
method in the SocialFacebook class.
FacebookMessage object, sent to the parameter of method contains recipients, dialog title and message field. As Facebook processes the information about recipients, Hive does not know the relevant data. Therefore, empty the recipients field when sending to the parameter. It is recommended to empty the field because Facebook may misunderstand the message as a spam due to the contents of dialog title or messages.
Followings are sample codes to send invitations to user’s Facebook friends.
API Reference: hive.SocialFacebook.showInvitationDialog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
// Set an invitation message through Facebook. FacebookMessage content = new FacebookMessage (); content.message = "Message"; content.dialogTitle = "Title"; content.recipients = null; // Not in use when inviting friends. content.data = "hidden payload data"; // Callback handler managing the result of sending Facebook invitation message. public void onShowInvitationDialogCB(ResultAPI result, List<String> invitedUserList) { if(result.isSuccess() && invitedUserList != null){ foreach(String invitedUser : invitedUserList){ // Search the user invited through Facebook. } } } // Expose an invitation dialog to send the Facebook invitation message. hive.SocialFacebook.showInvitationDialog(messageContent, onShowInvitationDialogCB); |
API Reference: SocialFacebook::showInvitationDialog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// Set an invitation message through Facebook. FacebookMessage content = new FacebookMessage(); content.message = "Message"; content.dialogTitle = "Title"; content.recipients = nullptr; // Not in use when inviting friends. content.data = "hidden payload data"; // Expose an invitation dialog to send the Facebook invitation message. SocialFacebook::showInvitationDialog(content, [=](ResultAPI result, std::vector<String> invitedUserList) { // Callback function managing the result of sending Facebook invitation message. if (result.isSuccess() && invitedUserList != nullptr) { for(String invitedUser : invitedUserList) { // Search the user invited through Facebook. } } }); |
API Reference: com.hive.SocialFacebook.showInvitationDialog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
// Set an invitation message through Facebook. SocialFacebook.SocialFacebookMessage content = new SocialFacebookMessage(); content.message = "Message"; content.dialogTitle = "Title"; content.recipients = null; // Not in use when inviting friends. content.data = "hidden payload data"; // Expose an invitation dialog to send the Facebook invitation message. SocialFacebook.showInvitationDialog(content, new SocialFacebook.ShowInvitationDialogListener() { @Override public void onShowInvitationDialog(ResultAPI result, List<String> invitedUserList) { // Callback listener managing the result of sending Facebook invitation message. if (result.isSuccess() && invitedUserList != null) { for (String invitedUser : invitedUserList) { // Search the user invited through Facebook. } } } }); |
API Reference: HIVESocialFacebook:showInvitationDialog
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
// Set an invitation message through Facebook. HIVESocialFacebookMessage *content = [[HIVESocialFacebookMessage alloc] init]; content.message = @"Message"; content.dialogTitle = @"Title"; content.recipients = nil; // Not in use when inviting friends. content.data = @"hidden payload data"; // Expose an invitation dialog to send the Facebook invitation message. [HIVESocialFacebook showInvitationDialog:content handler:^(HIVEResultAPI *result, NSArray<NSString *> *invitedUserList) { // Callback handler managing the result of sending Facebook invitation message. if([result isSuccess] && invitedUserList != nil) { for(NSString *invitedUser in invitedUserList) { // Search the user invited through Facebook. } } }]; |
Sending Messages to Facebook Friends
Implement sendMessageFacebook()
method in the SocialFacebook class to send messages to user’s Facebook friends. Make sure that the FacebookMessage object, sending to the first parameter of the method contains messages and additional information.
Followings are sample codes to send messages to one of Facebook friends
API Reference: hive.SocialFacebook.sendMessageFacebook
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// Set a Facebook message. FacebookMessage content = new FacebookMessage (); content.message = "Message"; content.dialogTitle = "Title"; content.recipients = new List<String> {"Facebook ID of a friend who receives Facebook message"}; content.data = "hidden payload data"; // Callback handler managing the result of sending Facebook message. public void onSendMessageFacebookCB(ResultAPI result) { if(result.isSuccess()){ // Success in API call. } } // Send the Facebook message. hive.SocialFacebook.sendMessageFacebook(content, onSendMessageFacebookCB); |
API Reference: SocialFacebook::sendMessageFacebook
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
// Set a Facebook message. FacebookMessage content; content.message = "Message"; content.dialogTitle = "Title"; std::vector<std::string> recipients = {"Facebook ID of a friend who receives Facebook message"}; content.recipients = recipients; content.data = "hidden payload data"; // Send the Facebook message. SocialFacebook::sendMessageFacebook(content, [=](ResultAPI result){ // Callback function managing the result of sending Facebook message.함수 if(result.isSuccess()) { // Success in API call. } }); |
API Reference: com.hive.SocialFacebook.sendMessageFacebook
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
// Set a Facebook message. SocialFacebook.SocialFacebookMessage content = new SocialFacebookMessage(); content.message = "Message"; content.dialogTitle = "Title"; content.recipients = new String[]{"Facebook ID of a friend who receives Facebook message"}; content.data = "hidden payload data"; // Send the Facebook message. SocialFacebook.sendMessageFacebook(content, new SocialFacebook.SendMessageFacebookListener() { @Override public void onSendMessageFacebook(ResultAPI result) { // Callback listener managing the result of sending Facebook message.리스너 if(result.isSuccess()){ // Success in API call. } } }); |
API Reference: HIVESocialFacebook:sendMessageFacebook
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
// Set a Facebook message. HIVESocialFacebookMessage *content = [[HIVESocialFacebookMessage alloc] init]; content.message = @"Message"; content.dialogTitle = @"Title"; content.recipients = [NSArray arrayWithObject:@"Facebook ID of a friend who receives Facebook message", nil]; content.data = @"hidden payload data"; // Send the Facebook message. [HIVESocialFacebook sendMessageFacebook:content handler:^(HIVEResultAPI *result) { // Callback handler managing the result of sending Facebook message. if([result isSuccess]){ // Success in API call. } }]; |
Writing Posts on News Feed
Hive provides a posting function as a method of advertising games. This function is available to post your News Feed on user’s Facebook Feed. News Feed is composed of title, posting and image. You can set a linked page when user taps the content.
Posting format on Facebook depends on the attaching image size. The recommended size is as follows. For more information about image size, see Facebook Developers site.
- Size: Bigger than 600×315 pixels
- Image aspect ratio: 1.91:1 (width:height. Opposite for vertical image)
Implement postFacebookWithContentURL()
method in the SocialFacebook class for users to post News Feed. Make sure that the contentURL(string), sending to the first parameter of the method contains contents URL which you want to write postings on News Feed.
Followings are sample codes to display editing page to post News Feed and write comments on Facebook.
API Reference: hive.SocialFacebook.postFacebookWithContentURL
1 2 3 4 5 6 7 8 9 10 11 12 13 |
// Content URL posting on Facebook News Feed. String contentURL = "contentURL"; // Callback handler managing the result of writing a post on Facebook News Feed. public void onPostFacebookCB(ResultAPI result) { if(result.isSuccess()){ // Success in API call. } } // Write the post on Facebook News Feed. hive.SocialFacebook.postFacebookWithContentURL(contentURL, onPostFacebookCB); |
API Reference: SocialFacebook::postFacebookWithContentURL
1 2 3 4 5 6 7 8 9 |
// Content URL posting on Facebook News Feed. std::string contentURL = "contentURL"; // Write the post on Facebook News Feed. SocialFacebook::postFacebookWithContentURL(contentURL, [=](ResultAPI result){ // Callback function managing the result of posting on Facebook News Feed. if(result.isSuccess()){ // Success in API call. } }); |
API Reference: com.hive.SocialFacebook.postFacebookWithContentURL
1 2 3 4 5 6 7 8 9 10 11 12 |
// Content URL posting on Facebook News Feed. String contentURL = "contentURL"; // Write the post on FAcebook News Feed. SocialFacebook.postFacebookWithContentURL(contentURL, new SocialFacebook.PostFacebookListener() { @Override public void onPostFacebook(ResultAPI result) { // Callback listener managing the result of posting on Facebook News Feed. if(result.isSuccess()){ // Success in API call. } } }); |
API Reference: HIVESocialFacebook::postFacebookWithContentURL:handler:
1 2 3 4 5 6 7 8 9 10 11 |
// Content URL posting on Facebook News Feed. NSString contentURL = @"contentURL"; // Write the post on Facebook News Feed. [HIVESocialFacebook postFacebookWithContentURL:content handler:^(HIVEResultAPI *result) { // Callback handler managing the result of writing a post on Facebook News Feed. if([result isSuccess]{ // Success in API call. }) }]; |
Reference: Main Class to Use Facebook Functions
Followings are the necessary object to implement SocialFacebook API which is available to use Facebook functions.
ProfileFacebook Class
ProfileFacebook class defines user’s Facebook profile, synced with the Facebook account, and the profile data is composed of the following information.
Name | Type | Description | Returned |
---|---|---|---|
uid | String | App-scoped User ID issued by Facebook | Always |
String | User’s email on Facebook | Provided when user sets an authority to share the user email on Facebook | |
username | String | User name on Facebook | Optional |
profileImageUrl | String | User profile image URL on Facebook | Optional |
FacebookMessage Class
FacebookMessage class defines Facebook messages toward friends.
Name | Type | Description | Required |
---|---|---|---|
recipients | String list
|
ID lists of Facebook friends to send messages CAUTION. Send the empty message in case of invitation |
Required |
dialogTitle | String(50) | The title of dialog box | Optional |
message | String | Message contents | Optional |
data | String(255) | Hidden data sending with messages | Optional |