Social Integration Service

Social connect with Facebook, Twitter, LinkedIn etc to post, update, invite, fetch, refer etc.

Import Statement
  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for Swift
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for Corona
  • create User Api for Cocos2DX
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
  1. <script type="text/javascript" src="App42-all-x.x.x.min.js">  
Initialize

In order to use the various functions available in a specific API, the developer has to initialize with App42API by passing the apiKey and the secretKey which will become available after the app creation from AppHQ dashboard.

Required Parameters

apiKey - The Application key given when the application was created. secretKey - The secret key corresponding to the application key given when the application was created.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for Swift
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for Corona
  • create User Api for Cocos2DX
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
  1. App42.initialize("API_KEY","SECRET_KEY");  
Build Service

After initialization, the developer will have to call the buildXXXService method on App42API to get the instance of the particular API that they wish to build. For example, to build an instance of Social Service, buildSocialService() method needs to be called.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for Swift
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for Corona
  • create User Api for Cocos2DX
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
  1. var socialService  = new App42Social();  
Update Facebook Status

Update the Facebook status of the specified user.

Required Parameters

userName - Name of the user for whom the status needs to be updated. status - Status that has to be updated.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for Swift
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for Corona
  • create User Api for Cocos2DX
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
  1. var userName = "Nick",                
  2. status = "Nick is using the App42 API",  
  3. social ;  
  4. App42.initialize("API_KEY","SECRET_KEY");  
  5. var socialService  = new App42Social();  
  6. socialService.updateFacebookStatus(userName, status,{  
  7.     success: function(object) {  
  8.     var response = JSON.parse(object);    
  9.         social = response.app42.response.social;  
  10.         console.log("userName is " + social.userName)  
  11.         console.log("status is " + social.status)  
  12.     },  
  13.     error: function(error) {  
  14.     }  
  15. });  
Get Facebook Friends Of User

This function returns a list of Facebook friends of the specified user by accessing their Facebook account. That user first has to link their app account to their Facebook profile.

Required Parameters

userName - Name of the user whose Facebook friends has to be retrieved.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for Swift
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for Corona
  • create User Api for Cocos2DX
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
  1. var userName = "Nick",      
  2. social;  
  3. App42.initialize("API_KEY","SECRET_KEY");  
  4. var socialService  = new App42Social();  
  5. socialService.getFacebookFriendsFromLinkUser(userName,{  
  6.     success: function(object) {  
  7.     var response = JSON.parse(object);    
  8.         social = response.app42.response.social;  
  9.         console.log("userName is " + social.userName)  
  10.     },  
  11.     error: function(error) {  
  12.     }  
  13. });  
Get Facebook Friends From AccessToken

This function returns a list of Facebook friends of the specified user using a given authorization token.

Required Parameters

accessToken - Facebook Access Token that has been received after authorization.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for Swift
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for Corona
  • create User Api for Cocos2DX
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
  1.                 
  2. var accessToken = "<Enter Facebook Access Token>",  
  3. social;  
  4. App42.initialize("API_KEY","SECRET_KEY");  
  5. var socialService  = new App42Social();  
  6. socialService.getFacebookFriendsFromAccessToken(accessToken,{  
  7.     success: function(object) {  
  8.     var response = JSON.parse(object);  
  9.             social = response.app42.response.social;  
  10.             console.log("accessToken is " + social.facebookAccessToken);  
  11.             var friends = social.friends;  
  12.             if (friends instanceof Array) {  
  13.                 for (var i = 0; i < friends.length; i++) {  
  14.                     console.log("Id : " + friends[i].id)  
  15.                     console.log("Installed : " + friends[i].installed)  
  16.                     console.log("Name : " + friends[i].name)  
  17.                     console.log("Picture : " + friends[i].picture)  
  18.                 }  
  19.             } else {  
  20.                 console.log("Id : " + friends.id)  
  21.                 console.log("Installed : " + friends.installed)  
  22.                 console.log("Name : " + friends.name)  
  23.                 console.log("Picture : " + friends.picture)  
  24.             }  
  25.         },  
  26.         error: function (error) {  
  27.         }  
  28. });  
Update Twitter Status

Update the Twitter status of the specified user.

Required Parameters

userName - Name of the user for whom the status needs to be updated. status - Status that has to be updated.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for Swift
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for Corona
  • create User Api for Cocos2DX
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
  1. var userName = "Nick",                
  2. status = "Nick is using the App42 API",  
  3. social ;  
  4. App42.initialize("API_KEY","SECRET_KEY");  
  5. var socialService  = new App42Social();  
  6. socialService.updateTwitterStatus(userName, status,{  
  7.     success: function(object) {  
  8.     var response = JSON.parse(object);    
  9.         social = response.app42.response.social;  
  10.         console.log("userName is " + social.userName)  
  11.         console.log("status is " + social.status)  
  12.     },  
  13.     error: function(error) {  
  14.     }  
  15. });  
Update Linkedin Status

Update the LinkedIn status of the specified user.

Required Parameters

userName - Name of the user for whom the status needs to be updated. status - Status that has to be updated.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for Swift
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for Corona
  • create User Api for Cocos2DX
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
  1. var userName = "Nick",                
  2. status = "Nick is using the App42 API",  
  3. social ;  
  4. App42.initialize("API_KEY","SECRET_KEY");  
  5. var socialService  = new App42Social();  
  6. socialService.updateLinkedInStatus(userName, status,{  
  7.     success: function(object) {  
  8.     var response = JSON.parse(object);    
  9.         social = response.app42.response.social;  
  10.         console.log("userName is " + social.userName)  
  11.         console.log("status is " + social.status)  
  12.     },  
  13.     error: function(error) {  
  14.     }  
  15. });  
Update Social Status On All

Update the status on all linked social accounts of the specified user.

Required Parameters

userName - Name of the user for whom the status needs to be updated. status - Status that has to be updated.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for Swift
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for Corona
  • create User Api for Cocos2DX
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
  1. var userName = "Nick",                
  2. status = "Nick is using the App42 API",  
  3. social ;  
  4. App42.initialize("API_KEY","SECRET_KEY");  
  5. var socialService  = new App42Social();  
  6. socialService.updateSocialStatusForAll(userName, status,{  
  7.     success: function(object) {  
  8.     var response = JSON.parse(object);    
  9.         social = response.app42.response.social;  
  10.         console.log("userName is " + social.userName)  
  11.         console.log("status is " + social.status)  
  12.     },  
  13.     error: function(error) {  
  14.     }  
  15. });  
Facebook Link Post

Share your link on Facebook based on access token.

Required Parameters

accessToken - Facebook Access Token that has been received after authorization. link - Link which has to be posted on Facebook wall. message - Message which has to be posted with the Link.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for Swift
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for Corona
  • create User Api for Cocos2DX
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
  1. var accessToken = "<Enter Facebook Access Token>",  
  2. link = "http://www.shephertz.com/",  
  3. message =  "Welcome to ShepHertz",  
  4. result;  
  5. App42.initialize("API_KEY","SECRET_KEY");  
  6. var socialService  = new App42Social();  
  7. socialService.facebookLinkPost(accessToken, link,message,{  
  8.     success: function(object) {  
  9.     var app42esponse = JSON.parse(object);    
  10.         result = app42esponse.app42.response;  
  11.         console.log("responses is " + result)  
  12.     },  
  13.     error: function(error) {  
  14.     }  
  15. });  
Facebook Link Post With Custom Thumbnail

Share your link on Facebook based on custom image and message.

Required Parameters

accessToken - Facebook Access Token that has been received after authorization. link - Link which has to be posted on Facebook. message - Message which has to be posted with the Link. pictureUrl - Your thumbnail image url which you want to share on Facebook. fileName - Name of your File which you have shared on Facebook. description - Description of your file and Post.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for Swift
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for Corona
  • create User Api for Cocos2DX
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
  1. var accessToken = "<Enter Facebook Access Token>",  
  2. link = "http://www.shephertz.com/",  
  3. message =  "Welcome to ShepHertz",  
  4. pictureUrl="https://apis.shephertz.com/images/cloud-api-services/app42-cloud-api-services.png",  
  5. fileName = "Buddy Image",  
  6. description =  "Welcome to ShepHertz Home Page",  
  7. app42Response;  
  8. App42.initialize("API_KEY","SECRET_KEY");  
  9. var socialService  = new App42Social();  
  10. socialService.facebookLinkPostWithCustomThumbnail(accessToken, link,message,pictureUrl, fileName, description,{  
  11.     success: function(object) {  
  12.     var result = JSON.parse(object);    
  13.         app42Response = result.app42.response;  
  14.         console.log("app42Response is : " + app42Response)  
  15.     },  
  16.     error: function(error) {  
  17.     }  
  18. });  
Get Facebook Profile

Fetch the profile info likes profile picture ,Facebook ID and name of the user based on Facebook access token.

Required Parameters

accessToken - Access Token of the user for which Profile Info has to be fetched.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for Swift
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for Corona
  • create User Api for Cocos2DX
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
  1. var accessToken = "<Enter Facebook Access Token>",  
  2. social;  
  3. App42.initialize("API_KEY","SECRET_KEY");  
  4. var socialService  = new App42Social();  
  5. socialService.getFacebookProfile(accessToken,{  
  6.     success: function(object) {  
  7.     var response = JSON.parse(object);    
  8.         social = response.app42.response.social;  
  9.         console.log("facebookProfileId is : " + social.me.id)  
  10.         console.log("facebookProfileName is : " + social.me.name)  
  11.         console.log("facebookProfileImage is : " + social.me.picture)  
  12.     },  
  13.     error: function(error) {  
  14.     }  
  15. });  
Facebook Publish Stream

Share your file on Facebook wall based on Facebook access token.

Required Parameters

accessToken - Facebook Access Token that has been received after authorization. fileName - Name of the file which you want to upload. filePath - Local path of the file. message - Message which has to be posted with the Link.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for Swift
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for Corona
  • create User Api for Cocos2DX
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
  1. var accessToken = "<Enter Facebook Access Token>",                
  2. fileName = "Buddy Image",  
  3. filePath = "https://apis.shephertz.com/images/cloud-api-services/app42-cloud-api-services.png",  
  4. message =  "Welcome to ShepHertz",  
  5. app42Response;  
  6. App42.initialize("API_KEY","SECRET_KEY");  
  7. var socialService  = new App42Social();  
  8. socialService.facebookPublishStream(accessToken, fileName, filePath, message,{  
  9.     success: function(object) {  
  10.     var response = JSON.parse(object);    
  11.         app42Response = response.app42.response;  
  12.         console.log("app42Response is : " + app42Response)  
  13.     },  
  14.     error: function(error) {  
  15.     }  
  16. });  
Exception Handling

The functions available under Social API can throw some exceptions in abnormal conditions. If a developer is linking the User’s Twitter account name who has not authorized the app to use his account, the function will throw the App42Exception (as shown below) with message as “Not Found” and the appErrorCode as “3800” and the details as “Twitter App Credentials (ConsumerKey / ConsumerSecret) does not exist”.

  • create User Api for Android
  • create User Api for Windows
  • create User Api for iOS
  • create User Api for Swift
  • create User Api for Java
  • create User Api for Unity
  • create User Api for JS
  • create User Api for Corona
  • create User Api for Cocos2DX
  • create User Api for .Net
  • create User Api for PHP
  • create User Api for Marmalade
  •  create User Api for Ruby
  •  create User Api for Flash
  1. var userName = "Nick",  
  2. appErrorCode ,  
  3. status = "Nick is using the App42 API";  
  4. App42.initialize("API_KEY","SECRET_KEY");  
  5. var socialService  = new App42Social();  
  6. socialService.updateTwitterStatus(userName, status,{  
  7.     success: function(object) {  
  8.     },  
  9.     error: function(error)   
  10.     {  
  11.         var socialObj = JSON.parse(error);  
  12.         appErrorCode = socialObj.app42Fault.appErrorCode;  
  13.         if(appErrorCode == 3800)  
  14.         {  
  15.             // Handle here for Not Found (Twitter App Credentials(ConsumerKey / ConsumerSecret) does not exist.)  
  16.         }  
  17.         else if(appErrorCode  == 3801)  
  18.         {  
  19.             // Handle here for Bad Request (The request is Unauthorized with the provided credentials.)  
  20.         }  
  21.         else if(appErrorCode  == 3802)  
  22.         {  
  23.             // Handle here for Not Found (Twitter User Access Credentials does not exist. Please use linkUserTwitterAccount API to link the User Twitter account.)  
  24.         }  
  25.         else if(appErrorCode  == 3803)  
  26.         {  
  27.             // Handle here for Bad Request (The Twitter Access Credentials are invalid.)  
  28.         }  
  29.         else if(appErrorCode == 1401)  
  30.         {  
  31.             // handle here for Client is not authorized  
  32.         }  
  33.         else if(appErrorCode == 1500)  
  34.         {  
  35.             // handle here for Internal Server Error  
  36.         }  
  37.     }  
  38. });  
Error Codes

Functions in Session API might throw exceptions with following HTTP and Application Error Codes (along with their descriptions):

1400 - BAD REQUEST - The Request parameters are invalid. 1401 - UNAUTHORIZED - Client is not authorized. 1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again. 3800 - NOT FOUND - Twitter App Credentials(ConsumerKey / ConsumerSecret) does not exist. 3802 - NOT FOUND - Twitter User Access Credentials does not exist. Please use linkUserTwitterAccount API to link the User Twitter account. 3803 - BAD REQUEST - The Twitter Access Credentials are invalid." + &lt;Exception Message>. 3804 - NOT FOUND - Facebook App Credentials(ConsumerKey/ConsumerSecret) does not exist. 3805 - BAD REQUEST - The Facebook Access Credentials are invalid + &lt;Received Facebook Exception Message>. 3806 - NOT FOUND - Facebook User Access Credentials does not exist. Please use linkUserFacebookAccount API to link the User facebook account. 3807 - NOT FOUND - LinkedIn App Credentials(ApiKey/SecretKey) does not exist. 3808 - BAD REQUEST - The Access Credentials are invalid + &lt;Exception Message>. 3809 - NOT FOUND - LinkedIn User Access Credentials does not exist. Please use linkUserLinkedInAccount API to link the User LinkedIn account. 3810 - NOT FOUND - Social App Credentials do not exist. 3811 - NOT FOUND - User Social Access Credentials do not exist. Please use linkUserXXXXXAccount API to link the User Social account.