// <summary> // Uploads an image to the user's social page on the given Provider. // Supported platforms: Facebook // // NOTE: This operation requires a successful login. // </summary> // <param name="provider">The <c>Provider</c> the given image should be uploaded to.</param> // <param name="message">Message to post with the image.</param> // <param name="filePath">Path of image file.</param> // <param name="payload">A string to receive when the function returns.</param> // <param name="reward">A <c>Reward</c> to give the user after a successful upload.</param> public static void UploadImage(Provider provider, string message, string filePath, string payload = "", Reward reward = null) { SocialProvider targetProvider = GetSocialProvider(provider); string userPayload = (payload == null) ? "" : payload; if (targetProvider == null) { return; } if (targetProvider.IsNativelyImplemented()) { //fallback to native string rewardId = reward != null ? reward.ID : ""; instance._uploadImage(provider, message, filePath, ProfilePayload.ToJSONObj(userPayload, rewardId).ToString()); } else { Texture2D tex2D = new Texture2D(4, 4); tex2D.LoadImage(File.ReadAllBytes(filePath)); string fileName = Path.GetFileName(filePath); UploadImage(provider, tex2D, fileName, message, userPayload, reward); } }
/// <summary> /// Fetches UserProfiles of contacts of the current user. /// Supported platforms: Facebook, Twitter, Google+. /// Missing contact information for Twitter: email, gender, birthday. /// Missing contact information for Google+: username, email, gender, bithday /// /// NOTE: This operation requires a successful login. /// </summary> /// <param name="provider">The <c>Provider</c> to fetch contacts from.</param> /// <param name="payload">A string to receive when the function returns.</param> public static void GetContacts(Provider provider, string payload = "") { SocialProvider targetProvider = GetSocialProvider(provider); string userPayload = (payload == null) ? "" : payload; if (targetProvider == null) { return; } if (targetProvider.IsNativelyImplemented()) { //fallback to native instance._getContacts(provider, ProfilePayload.ToJSONObj(userPayload).ToString()); } else { ProfileEvents.OnGetContactsStarted(provider, userPayload); targetProvider.GetContacts( /* success */ (List <UserProfile> profiles) => { ProfileEvents.OnGetContactsFinished(provider, profiles, userPayload); }, /* fail */ (string message) => { ProfileEvents.OnGetContactsFailed(provider, message, userPayload); } ); } }
/// <summary> /// Uploads an image to the user's social page on the given Provider with confirmation dialog. /// Supported platforms: Facebook, Twitter, Google+ /// /// NOTE: This operation requires a successful login. /// </summary> /// <param name="provider">The <c>Provider</c> the given image should be uploaded to.</param> /// <param name="message">Message to post with the image.</param> /// <param name="fileName">Name of image file with extension (jpeg/pgn).</param> /// <param name="imageBytes">Image bytes.</param> /// <param name="jpegQuality">Image quality, number from 0 to 100. 0 meaning compress for small size, 100 meaning compress for max quality. /// Some formats, like PNG which is lossless, will ignore the quality setting /// <param name="payload">A string to receive when the function returns.</param> /// <param name="reward">A <c>Reward</c> to give the user after a successful upload.</param> /// <param name="customMessage">The message to show in the dialog</param> public static void UploadImageWithConfirmation(Provider provider, string message, string fileName, byte[] imageBytes, int jpegQuality, string payload = "", Reward reward = null, string customMessage = null) { SocialProvider targetProvider = GetSocialProvider(provider); string userPayload = (payload == null) ? "" : payload; if (targetProvider == null) { return; } if (targetProvider.IsNativelyImplemented()) { string rewardId = reward != null ? reward.ID: ""; instance._uploadImage(provider, message, fileName, imageBytes, jpegQuality, ProfilePayload.ToJSONObj(userPayload, rewardId).ToString(), true, customMessage); } else { // TODO: Support showConfirmation ProfileEvents.OnSocialActionStarted(provider, SocialActionType.UPLOAD_IMAGE, userPayload); targetProvider.UploadImage(imageBytes, fileName, message, /* success */ () => { if (reward != null) { reward.Give(); } ProfileEvents.OnSocialActionFinished(provider, SocialActionType.UPLOAD_IMAGE, userPayload); }, /* fail */ (string error) => { ProfileEvents.OnSocialActionFailed(provider, SocialActionType.UPLOAD_IMAGE, error, userPayload); }, /* cancel */ () => { ProfileEvents.OnSocialActionCancelled(provider, SocialActionType.UPLOAD_IMAGE, userPayload); } ); } }
/// <summary> /// Updates the user's status on the given provider. /// Supported platforms: Facebook, Twitter, Google+ /// /// NOTE: This operation requires a successful login. /// </summary> /// <param name="provider">The <c>Provider</c> the given status should be posted to.</param> /// <param name="status">The actual status text.</param> /// <param name="payload">A string to receive when the function returns.</param> /// <param name="reward">A <c>Reward</c> to give the user after a successful post.</param> public static void UpdateStatus(Provider provider, string status, string payload = "", Reward reward = null) { SocialProvider targetProvider = GetSocialProvider(provider); string userPayload = (payload == null) ? "" : payload; if (targetProvider == null) { return; } if (targetProvider.IsNativelyImplemented()) { //fallback to native string rewardId = reward != null ? reward.ID : ""; instance._updateStatus(provider, status, ProfilePayload.ToJSONObj(userPayload, rewardId).ToString()); } else { ProfileEvents.OnSocialActionStarted(provider, SocialActionType.UPDATE_STATUS, userPayload); targetProvider.UpdateStatus(status, /* success */ () => { ProfileEvents.OnSocialActionFinished(provider, SocialActionType.UPDATE_STATUS, userPayload); if (reward != null) { reward.Give(); } }, /* fail */ (string error) => { ProfileEvents.OnSocialActionFailed(provider, SocialActionType.UPDATE_STATUS, error, userPayload); } ); } }
/// <summary> /// Fetches UserProfiles of contacts of the current user. /// Supported platforms: Facebook, Twitter, Google+. /// Missing contact information for Twitter: email, gender, birthday. /// Missing contact information for Google+: username, email, gender, bithday /// /// NOTE: This operation requires a successful login. /// </summary> /// <param name="provider">The <c>Provider</c> to fetch contacts from.</param> /// <param name="pageNumber">The contacts' page number to get.</param> /// <param name="payload">A string to receive when the function returns.</param> public static void GetContacts(Provider provider, int pageNumber = 0, string payload = "") { SocialProvider targetProvider = GetSocialProvider(provider); string userPayload = (payload == null) ? "" : payload; if (targetProvider == null) { return; } if (targetProvider.IsNativelyImplemented()) { //fallback to native //TODO: add pageNumber here when implemented natively instance._getContacts(provider, ProfilePayload.ToJSONObj(userPayload).ToString()); } else { ProfileEvents.OnGetContactsStarted(provider, pageNumber, userPayload); targetProvider.GetContacts(pageNumber, /* success */ (SocialPageData <UserProfile> contactsData) => { ProfileEvents.OnGetContactsFinished(provider, contactsData, userPayload); }, /* fail */ (string message) => { ProfileEvents.OnGetContactsFailed(provider, pageNumber, message, userPayload); } ); } }
/// <summary> /// Retrieves a list of the user's feed entries from the supplied provider. /// Upon a successful retrieval of feed entries the user will be granted the supplied reward. /// /// NOTE: This operation requires a successful login. /// </summary> /// <param name="provider">The <c>Provider</c> on which to retrieve a list of feed entries.</param> /// <param name="fromStart">Should we reset pagination or request the next page.</param> /// <param name="payload">A string to receive when the function returns.</param> /// <param name="reward">The reward which will be granted to the user upon a successful retrieval of feed.</param> public static void GetFeed(Provider provider, bool fromStart = false, string payload = "", Reward reward = null) { SocialProvider targetProvider = GetSocialProvider(provider); string userPayload = (payload == null) ? "" : payload; if (targetProvider == null) { return; } if (targetProvider.IsNativelyImplemented()) { string rewardId = reward != null ? reward.ID: ""; //fallback to native instance._getFeed(provider, fromStart, ProfilePayload.ToJSONObj(userPayload, rewardId).ToString()); } else { ProfileEvents.OnGetFeedStarted(provider); targetProvider.GetFeed(fromStart, /* success */ (SocialPageData <String> feeds) => { if (reward != null) { reward.Give(); } ProfileEvents.OnGetFeedFinished(provider, feeds); }, /* fail */ (string message) => { ProfileEvents.OnGetFeedFailed(provider, message); }); } }
/// <summary> /// Logs the user into the given provider. /// Supported platforms: Facebook, Twitter, Google+ /// </summary> /// <param name="provider">The provider to log in to.</param> /// <param name="payload">A string to receive when the function returns.</param> /// <param name="reward">A <c>Reward</c> to give the user after a successful login.</param> public static void Login(Provider provider, string payload = "", Reward reward = null) { SoomlaUtils.LogDebug(TAG, "Trying to login with provider " + provider.ToString()); SocialProvider targetProvider = GetSocialProvider(provider); string userPayload = (payload == null) ? "" : payload; if (targetProvider == null) { SoomlaUtils.LogError(TAG, "Provider not supported or not set as active: " + provider.ToString()); return; } if (targetProvider.IsNativelyImplemented()) { //fallback to native string rewardId = reward != null ? reward.ID : ""; instance._login(provider, ProfilePayload.ToJSONObj(userPayload, rewardId).ToString()); } else { setLoggedInForProvider(provider, false); ProfileEvents.OnLoginStarted(provider, userPayload); targetProvider.Login( /* success */ () => { targetProvider.GetUserProfile((UserProfile userProfile) => { StoreUserProfile(userProfile); setLoggedInForProvider(provider, true); ProfileEvents.OnLoginFinished(userProfile, userPayload); if (reward != null) { reward.Give(); } }, (string message) => { ProfileEvents.OnLoginFailed(provider, message, userPayload); }); }, /* fail */ (string message) => { ProfileEvents.OnLoginFailed(provider, message, userPayload); }, /* cancel */ () => { ProfileEvents.OnLoginCancelled(provider, userPayload); } ); } }
/// <summary> /// Posts a full story to the user's social page on the given Provider with confirmation dialog. /// A story contains a title, description, image and more. /// Supported platforms: Facebook (full support), /// Twitter and Google+ (partial support - message and link only) /// /// NOTE: This operation requires a successful login. /// </summary> /// <param name="provider">The <c>Provider</c> the given story should be posted to.</param> /// <param name="message">A message that will be shown along with the story.</param> /// <param name="name">The name (title) of the story.</param> /// <param name="caption">A caption.</param> /// <param name="description">A description.</param> /// <param name="link">A link to a web page.</param> /// <param name="pictureUrl">A link to an image on the web.</param> /// <param name="payload">A string to receive when the function returns.</param> /// <param name="reward">A <c>Reward</c> to give the user after a successful post.</param> /// <param name="customMessage">The message to show in the dialog</param> public static void UpdateStoryWithConfirmation(Provider provider, string message, string name, string caption, string description, string link, string pictureUrl, string payload = "", Reward reward = null, string customMessage = null) { SocialProvider targetProvider = GetSocialProvider(provider); string userPayload = (payload == null) ? "" : payload; if (targetProvider == null) { return; } if (targetProvider.IsNativelyImplemented()) { //fallback to native string rewardId = reward != null ? reward.ID: ""; instance._updateStory(provider, message, name, caption, description, link, pictureUrl, ProfilePayload.ToJSONObj(userPayload, rewardId).ToString(), true, customMessage); } else { // TODO: Support showConfirmation ProfileEvents.OnSocialActionStarted(provider, SocialActionType.UPDATE_STORY, userPayload); targetProvider.UpdateStory(message, name, caption, link, pictureUrl, /* success */ () => { if (reward != null) { reward.Give(); } ProfileEvents.OnSocialActionFinished(provider, SocialActionType.UPDATE_STORY, userPayload); }, /* fail */ (string error) => { ProfileEvents.OnSocialActionFailed(provider, SocialActionType.UPDATE_STORY, error, userPayload); }, /* cancel */ () => { ProfileEvents.OnSocialActionCancelled(provider, SocialActionType.UPDATE_STORY, userPayload); } ); } }
public static void Invite(Provider provider, string inviteMessage, string dialogTitle = null, string payload = "", Reward reward = null) { SocialProvider targetProvider = GetSocialProvider(provider); string userPayload = (payload == null) ? "" : payload; if (targetProvider == null) { return; } if (targetProvider.IsNativelyImplemented()) { //fallback to native string rewardId = reward != null ? reward.ID: ""; //TODO: add invite implementation when implemented in native instance._invite(provider, inviteMessage, dialogTitle, ProfilePayload.ToJSONObj(userPayload, rewardId).ToString()); } else { ProfileEvents.OnInviteStarted(provider, userPayload); targetProvider.Invite(inviteMessage, dialogTitle, /* success */ (string requestId, List <string> invitedIds) => { if (reward != null) { reward.Give(); } ProfileEvents.OnInviteFinished(provider, requestId, invitedIds, userPayload); }, /* fail */ (string message) => { ProfileEvents.OnInviteFailed(provider, message, userPayload); }, /* cancel */ () => { ProfileEvents.OnInviteCancelled(provider, userPayload); }); } }