/// <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> /// Logs the user out of the given provider. /// Supported platforms: Facebook, Twitter, Google+ /// /// NOTE: This operation requires a successful login. /// </summary> /// <param name="provider">The provider to log out from.</param> public static void Logout(Provider provider) { SocialProvider targetProvider = GetSocialProvider(provider); if (targetProvider == null) { return; } if (targetProvider.IsNativelyImplemented()) { //fallback to native instance._logout(provider); } else { ProfileEvents.OnLogoutStarted(provider); targetProvider.Logout( /* success */ () => { UserProfile userProfile = GetStoredUserProfile(provider); if (userProfile != null) { RemoveUserProfile(userProfile); } ProfileEvents.OnLogoutFinished(provider); }, /* fail */ (string message) => { ProfileEvents.OnLogoutFailed(provider, message); } ); } }
// <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> /// 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> /// 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; } // 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); } ); }
private static void login(Provider provider, bool autoLogin, 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; } setLoggedInForProvider(provider, false); ProfileEvents.OnLoginStarted(provider, autoLogin, userPayload); targetProvider.Login( /* success */ () => { targetProvider.GetUserProfile((UserProfile userProfile) => { StoreUserProfile(userProfile); setLoggedInForProvider(provider, true); ProfileEvents.OnLoginFinished(userProfile, autoLogin, userPayload); if (reward != null) { reward.Give(); } }, (string message) => { ProfileEvents.OnLoginFailed(provider, message, autoLogin, userPayload); }); }, /* fail */ (string message) => { ProfileEvents.OnLoginFailed(provider, message, autoLogin, userPayload); }, /* cancel */ () => { ProfileEvents.OnLoginCancelled(provider, autoLogin, userPayload); } ); }
public static bool IsProviderNativelyImplemented(Provider provider) { SocialProvider targetProvider = GetSocialProvider(provider); if (targetProvider != null) { return(targetProvider.IsNativelyImplemented()); } return(false); }
private static SocialProvider GetSocialProvider(Provider provider) { SocialProvider result = null; providers.TryGetValue(provider, out result); // if (result == null) { // throw new ProviderNotFoundException(); // } return(result); }
// TODO: this is irrelevant for now. Will be updated soon. // public static void AddAppRequest(Provider provider, string message, string[] to, string extraData, string dialogTitle) { // providers[provider].AppRequest(message, to, extraData, dialogTitle, // /* success */ (string requestId, List<string> recipients) => { // string requestsStr = KeyValueStorage.GetValue("soomla.profile.apprequests"); // List<string> requests = new List<string>(); // if (!string.IsNullOrEmpty(requestsStr)) { // requests = requestsStr.Split(',').ToList(); // } // requests.Add(requestId); // KeyValueStorage.SetValue("soomla.profile.apprequests", string.Join(",", requests.ToArray())); // KeyValueStorage.SetValue(requestId, string.Join(",", recipients.ToArray())); // ProfileEvents.OnAddAppRequestFinished(provider, requestId); // }, // /* fail */ (string errMsg) => { // ProfileEvents.OnAddAppRequestFailed(provider, errMsg); // }); // } /// <summary> /// Will fetch posts from user feed /// /// </summary> /// <param name="provider">Provider.</param> /// <param name="reward">Reward.</param> // public static void GetFeed(Provider provider, Reward reward) { // // // TODO: implement with FB SDK // // } /// <summary> /// Likes the page (with the given name) of the given provider. /// Supported platforms: Facebook, Twitter, Google+. /// /// NOTE: This operation requires a successful login. /// </summary> /// <param name="provider">The provider that the page belongs to.</param> /// <param name="pageName">The name of the page to like.</param> /// <param name="reward">A <c>Reward</c> to give the user after he/she likes the page.</param> public static void Like(Provider provider, string pageName, Reward reward = null) { SocialProvider targetProvider = GetSocialProvider(provider); if (targetProvider != null) { targetProvider.Like(pageName); if (reward != null) { reward.Give(); } } }
/// <summary> /// Checks if the user is logged into the given provider. /// Supported platforms: Facebook, Twitter, Google+ /// </summary> /// <returns>If is logged into the specified provider, returns <c>true</c>; /// otherwise, <c>false</c>.</returns> /// <param name="provider">The provider to check if the user is logged into.</param> public static bool IsLoggedIn(Provider provider) { SocialProvider targetProvider = GetSocialProvider(provider); if (targetProvider == null) { return(false); } if (targetProvider.IsNativelyImplemented()) { //fallback to native return(instance._isLoggedIn(provider)); } return(targetProvider.IsLoggedIn()); }
/// <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); }); } }
// public static void UploadImage(Provider provider, string message, string filename, // byte[] imageBytes, int quality, Reward reward) { // instance._uploadImage(provider, message, filename, imageBytes, quality, reward); // } // /// <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="tex2D">Texture2D for image.</param> /// <param name="fileName">Name of image file.</param> /// <param name="message">Message to post with the image.</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, Texture2D tex2D, string fileName, string message, string payload = "", Reward reward = null) { SocialProvider targetProvider = GetSocialProvider(provider); string userPayload = (payload == null) ? "" : payload; if (targetProvider == null) { return; } if (targetProvider.IsNativelyImplemented()) { //fallback to native ProfileEvents.OnSocialActionFailed(provider, SocialActionType.UPLOAD_IMAGE, "Image uploading is not supported with Texture for natively implemented social providers", userPayload); } else { ProfileEvents.OnSocialActionStarted(provider, SocialActionType.UPLOAD_IMAGE, userPayload); targetProvider.UploadImage(tex2D.EncodeToPNG(), fileName, message, /* success */ () => { ProfileEvents.OnSocialActionFinished(provider, SocialActionType.UPLOAD_IMAGE, userPayload); if (reward != null) { reward.Give(); } }, /* fail */ (string error) => { ProfileEvents.OnSocialActionFailed(provider, SocialActionType.UPLOAD_IMAGE, error, userPayload); }, /* cancel */ () => { ProfileEvents.OnSocialActionCancelled(provider, SocialActionType.UPLOAD_IMAGE, userPayload); } ); } }
internal static void ProviderBecameReady(SocialProvider socialProvider) { --unreadyProviders; TryFireProfileInitialized(); }