App42 Cloud API

Android Cloud SDK

Social

In order to use the various functions available under a particular API, a developer will have to create an instance of ServiceAPI by passing the apiKey and the secretKey which has been received while creating an app.

ServiceAPI api = new ServiceAPI("<API_KEY>","<SECRET_KEY>");                              

After initialization, developer needs to call the buildXXXService method on ServiceAPI instance to get the instance of the particular API that you wish to build. For example, To build an instance of FacebookService, buildFacebookService() method needs to be called.

SocialService socialService = api.BuildSocialService();

Once the API instance has been retrieved, You are ready to use the functions available for that particular API.

The methods available under a particular API will return the domain object (like Facebook , Twitter or LinkedIn in this case) as a response which will have the accessor / mutator to access the available properties for that object. You can get the response in the form of JSON as well. We have provided the JSON response with every function detail which can be retrieved by calling the toString() on the returned object.

String userName = "Nick";	
String accessToken = "TWITTER ACCESS TOKEN";
String accessTokenSecret = "TWITTER ACCESS TOKEN SECRET";					
String consumerKey = "TWITTER CONSUMER KEY";
String consumerSecret = "TWITTER CONSUMER SECRET"; 
		
Social social = socialService.linkUserTwitterAccount(userName,consumerKey,consumerSecret,accessToken,accessTokenSecret);  /* returns the Social object. */ 
System.out.println("userName is " + social.getUserName());
System.out.println("twitterConsumerKey is " + social.getTwitterConsumerKey());
System.out.println("twitterConsumerSecret is " + social.getTwitterConsumerSecret());
System.out.println("twitterAccessToken is " + social.getTwitterAccessToken());
System.out.println("twitterAccessTokenSecret is " + social.getTwitterAccessTokenSecret());
String jsonResponse = social.toString(); /* returns the response in JSON format. (as shown below)*/   

The functions available under Social API can throw some exceptions in abnormal conditions. Example of the same has been given below.

E.g. If App developer is linking the User 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".

String userName = "Nick";
String status = "Review All Social Api By Nick";

try
{
	Social social = socialService.updateTwitterStatus(userName, status);
}
catch(App42Exception ex) 
{
	int appErrorCode = ex.getAppErrorCode();
	int httpErrorCode = ex.getHttpErrorCode();
	if(appErrorCode == 3800)
	{
		// Handle here for Not Found (Twitter App Credentials(ConsumerKey / ConsumerSecret) does not exist.)
	}
	else if(appErrorCode  == 3801)
	{
		// Handle here for Bad Request (The request is Unauthorized with the provided credentials.)
	}
	else if(appErrorCode  == 3802)
	{
		// Handle here for Not Found (Twitter User Access Credentials does not exist. Please use linkUserTwitterAccount API to link the User Twitter account.)
	}
	else if(appErrorCode  == 3803)
	{
		// Handle here for Bad Request (The Twitter Access Credentials are invalid.)
	}
	else if(appErrorCode == 1401)
	{
		// handle here for Client is not authorized
	}
	else if(appErrorCode == 1500)
	{
		// handle here for Internal Server Error
	}
	String jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/	
}                             
{
    "app42Fault": {
        "httpErrorCode": 400,
        "appErrorCode": 3800,
        "message": "Not Found",
        "details": "Twitter App Credentials(ConsumerKey / ConsumerSecret) does not exist"
    }
}

Below are the HTTP Error Codes and their description, the function under the User API can throw.

/*
1400 - BAD REQUEST - The Request parameters are invalid
1401 - UNAUTHORIZED - Client is not authorized
1500 - INTERNAL SERVER ERROR - Internal Server Error. Please try again	
*/	

Below are the Application Error Codes and their description, the function under the User API can throw.

/*
3800 - NOT FOUND - Twitter App Credentials(ConsumerKey / ConsumerSecret) does not exist.
3801 - BAD REQUEST - The request is Unauthorized with the provided credentials.
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." + <Exception Message>.
3804 - NOT FOUND - Facebook App Credentials(ConsumerKey / ConsumerSecret) does not exist.
3805 - BAD REQUEST - The Facebook Access Credentials are invalid.
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.
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.
*/

Various functions available under Social API has been explained below.

public Social linkUserFacebookAccount(String userName, String accessToken) throws App42Exception

Links the User Facebook access credentials to the App User account.

Parameters:

userName - Name of the user whose Facebook account to be linked
accessToken - Facebook Access Token that has been received after authorisation

Returns:

The Social object

Response: Social Object

For more details click Exception


String userName = "Nick";                  
String accessToken = "FACEBOOK ACCESS TOKEN";

Social social = socialService.linkUserFacebookAccount(userName, accessToken);  /* returns the Facebook object. */ 
System.out.println("UserName" + social.getUserName());
System.out.println("FacebookAccessToken" + social.getFacebookAccessToken());
String jsonResponse = social.toString(); /* returns the response in JSON format. (as shown below)*/   

{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "facebookAccessToken": "FACEBOOK ACCESS TOKEN"
            }
        }
    }
}                                            
public Social linkUserFacebookAccount(String userName, String accessToken, String appId, String appSecret) throws App42Exception

Links the User Facebook access credentials to the App User account.

Parameters:

userName - Name of the user whose Facebook account to be linked
accessToken - Facebook Access Token that has been received after authorisation
appId - Facebook App Id
appSecret - Facebook App Secret
accessToken - Facebook Access Token that has been received after authorisation

Returns:

The Social object

Response: Social Object

For more details click Exception


String userName = "Nick"; 
String accessToken = "FACEBOOK ACCESS TOKEN";   
String appId = "FACEBOOK APP ID";
String appSecret = "FACEBOOK APP SECRET";                    

Social social = socialService.linkUserFacebookAccount(userName, accessToken, appId, appSecret);  /* returns the Facebook object. */ 
System.out.println("UserName" + social.getUserName());
System.out.println("FacebookAccessToken" + social.getFacebookAccessToken());
System.out.println("FacebookAppId" + social.getFacebookAppId());
System.out.println("FacebookAppSecret" + social.getFacebookAppSecret());
String jsonResponse = social.toString(); /* returns the response in JSON format. (as shown below)*/    

{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "facebookAccessToken": "FACEBOOK ACCESS TOKEN",
                "facebookAppId": "FACEBOOK APP ID",
                "facebookAppSecret": "FACEBOOK APP SECRET"
            }
        }
    }
}       
public Social updateFacebookStatus(String userName, String status) throws App42Exception

Updates the Facebook status of the specified user.

Parameters:

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

Returns:

The Social object

Response: Social Object

Exception:

The method throws the following exception with the error code.
/*
3804 - NOT FOUND - Facebook App Credentials(ConsumerKey / ConsumerSecret) does not exist.
3805 - BAD REQUEST - The Facebook Access Credentials are invalid.
3806 - NOT FOUND - Facebook User Access Credentials does not exist. Please use linkUserFacebookAccount API to link the User facebook account.
*/	
For more details click Exception
String userName = "Nick";
String status = "Reviewing Faecbook APIs By Nick";

Social social = socialService.updateFacebookStatus(userName, status);  /* returns the Facebook object. */ 
System.out.println("userName is " + social.getUserName());
System.out.println("status is " + social.getStatus()); 
String jsonResponse = social.toString(); /* returns the response in JSON format. (as shown below)*/   
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "status": "Reviewing Faecbook APIs By Nick"
            }
        }
    }
}          
public Social getFacebookFriendsFromLinkUser(String userName) throws App42Exception

This function returns a list of facebook friends of the specified user by accessing the facebook account.

Parameters:

userName - Name of the user whose Facebook friends account has to be retrieve

Returns:

Social object

Response: Social Object

Exception:

The method throws the following exception with the error code.
/*
3804 - NOT FOUND - Facebook App Credentials(ConsumerKey / ConsumerSecret) does not exist.
3805 - BAD REQUEST - The Facebook Access Credentials are invalid.
3806 - NOT FOUND - Facebook User Access Credentials does not exist. Please use linkUserFacebookAccount API to link the User facebook account.
*/ 	        
For more details click Exception
String userName = "Nick";

Social social = socialService.getFacebookFriendsFromLinkUser(userName);  /* returns the Social object. */ 
System.out.println("userName is " + social.getUserName());
ArrayList<Friends> friendsList = social.getFriendList();
for(Friends friends : friendsList)
{
	System.out.println("Friend Name is " + friends.getName());
	System.out.println("Friend Id is " + friends.getId());
}
String jsonResponse = social.toString(); /* returns the response in JSON format. (as shown below)*/   
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "friends": [
                    {
                        "id": "xxxxxxxxx",
                        "name": "Joe Lopez",
                        "picture": "http://profile.ak.fbcdn.net/hprofile-ak-prn1/xxxxxxxxxx.jpg",
                        "installed": false
                    },
                    {
                        "id": "xxxxxxxxxx",
                        "name": "Robert",
                        "picture": "http://profile.ak.fbcdn.net/hprofile-ak-prn1/xxxxxxxxxxxxx.jpg",
                        "installed": true
                    }
                ]
            }
        }
    }
} 
public Social getFacebookFriendsFromAccessToken(String accessToken) throws App42Exception

This function returns a list of facebook friends of the specified user using a given authorization token. To get the friend list here, user needs not to log into the facebook account.

Parameters:

accessToken - Facebook Access Token that has been received after authorization

Returns:

Social object

Response: Social Object

Exception:

The method throws the following exception with the error code.
/*
3805 - BAD REQUEST - The Facebook Access Credentials are invalid.
*/ 	        
For more details click Exception
String accessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

Social social = socialService.getFacebookFriendsFromAccessToken(accessToken);  /* returns the Social object. */ 
System.out.println("Access Token is " + social.getFacebookAccessToken());
ArrayList<Friends> friendsList = social.getFriendList();
for(Friends friends : friendsList)
{
	System.out.println("Friend Name is " + friends.getName());
	System.out.println("Friend Id is " + friends.getId());
}
String jsonResponse = social.toString(); /* returns the response in JSON format. (as shown below)*/   
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "facebookAccessToken": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
                "friends": [
                    {
                        "id": "xxxxxxxxx",
                        "name": "Joe Lopez",
                        "picture": "http://profile.ak.fbcdn.net/hprofile-ak-prn1/xxxxxxxxxx.jpg",
                        "installed": false
                    },
                    {
                        "id": "xxxxxxxxxx",
                        "name": "Robert",
                        "picture": "http://profile.ak.fbcdn.net/hprofile-ak-prn1/xxxxxxxxxxxxx.jpg",
                        "installed": true
                    }
                ]
            }
        }
    }
} 
public Social linkUserTwitterAccount(String userName, String accessToken, String accessTokenSecret) throws App42Exception

Links the User Twitter access credentials to the App User account.

Parameters:

userName - Name of the user whose Twitter account to be linked
accessToken - Twitter Access Token that has been received after authorisation
accessTokenSecret - Twitter Access Token Secret that has been received after authorisation

Returns:

The Social object

Response: Social Object

For more details click Exception
String userName = "Nick";
String accessToken = "TWITTER ACCESS TOKEN";
String accessTokenSecret = "TWITTER ACCESS TOKEN SECRET"; 
		
Social social = socialService.linkUserTwitterAccount(userName,accessToken,accessTokenSecret);  /* returns the Twitter object. */ 
System.out.println("UserName" + social.getUserName());
System.out.println("TwitterAccessToken" + social.getTwitterAccessToken());
System.out.println("TwitterAccessTokenSecret" + social.getTwitterAccessTokenSecret());
String jsonResponse = social.toString(); /* returns the response in JSON format. (as shown below)*/ 
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "twitterAccessToken": "TWITTER ACCESS TOKEN",
                "twitterAccessTokenSecret": "TWITTER ACCESS TOKEN SECRET"
            }
        }
    }
}
public Social linkUserTwitterAccount(String userName, String accessToken, String accessTokenSecret, String consumerKey, String consumerSecret) throws App42Exception

Links the User Twitter access credentials to the App User account.

Parameters:

userName - Name of the user whose Twitter account to be linked
accessToken - Twitter Access Token that has been received after authorisation
accessTokenSecret - Twitter Access Token Secret that has been received after authorisation
consumerKey - Twitter App Consumer Key
consumerSecret - Twitter App Consumer Secret

Returns:

The Social object

Response: Social Object

For more details click Exception
String userName = "Nick";		
String accessToken = "TWITTER ACCESS TOKEN";
String accessTokenSecret = "TWITTER ACCESS TOKEN SECRET"; 				
String consumerKey = "TWITTER CONSUMER KEY";
String consumerSecret = "TWITTER CONSUMER SECRET";

Social social = socialService.linkUserTwitterAccount(userName,consumerKey,consumerSecret,accessToken,accessTokenSecret);  /* returns the Twitter object. */ 
System.out.println("UserName" + social.getUserName());
System.out.println("TwitterAccessToken" + social.getTwitterAccessToken());
System.out.println("TwitterAccessTokenSecret" + social.getTwitterAccessTokenSecret());
System.out.println("TwitterConsumerKey" + social.getTwitterConsumerKey());
System.out.println("TwitterConsumerSecret" + social.getTwitterConsumerSecret());
String jsonResponse = social.toString(); /* returns the response in JSON format. (as shown below)*/ 
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "twitterAccessToken": "TWITTER ACCESS TOKEN",
                "twitterAccessTokenSecret": "TWITTER ACCESS TOKEN SECRET",
                "twitterConsumerKey": "TWITTER CONSUMER KEY",
                "twitterConsumerSecret": "TWITTER CONSUMER SECRET"
            }
        }
    }
}
                                            
public Social updateTwitterStatus(String userName, String status) throws App42Exception

Updates the Twitter status of the specified user.

Parameters:

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

Returns:

The Social object

Response: Twitter Object

Exception:

The method throws the following exception with the error code.
/*
3800 - NOT FOUND - Twitter App Credentials(ConsumerKey / ConsumerSecret) does not exist. 
3801 - BAD REQUEST - The request is Unauthorized with the provided credentials. 
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." + <Exception Message>. 
*/ 	       
For more details click Exception
String userName = "Nick";
String status = "Reviewing Twitter APIs By Nick";	

Socail social = socialService.updateTwitterStatus(userName, status);  /* returns the Twitter object. */ 
System.out.println("userName is " + social.getUserName());
System.out.println("status is " + social.getStatus());
String jsonResponse = social.toString(); /* returns the response in JSON format. (as shown below)*/ 
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "status": "Reviewing Twitter APIs By Nick"
            }
        }
    }
}                                          
public Social linkUserLinkedInAccount(String userName, String accessToken, String accessTokenSecret)throws App42Exception

Links the User LinkedIn access credentials to the App User account.

Parameters:

userName - Name of the user whose LinkedIn account to be linked
accessToken - LinkedIn Access Token that has been received after authorisation
accessTokenSecret - LinkedIn Access Token Secret that has been received after authorisation

Returns:

The Social object

Response: Social Object

For more details click Exception
String userName = "Nick";	
String accessToken = "LINKEDIN ACCESS TOKEN";
String accessTokenSecret = "LINKEDIN ACCESS TOKEN SECRET";
		
Social social = socialService.linkUserLinkedInAccount(userName, accessToken, accessTokenSecret);  /* returns the Twitter object. */ 
System.out.println("UserName" + social.getUserName());
System.out.println("LinkedinAccessToken" + social.getLinkedinAccessToken());
System.out.println("LinkedinAccessTokenSecret" + social.getLinkedinAccessTokenSecret());
String jsonResponse = social.toString(); /* returns the response in JSON format. (as shown below)*/  
{
    "app42": {
        "response": {
            "success": true,
            "social": {  
                "userName": "Nick",
                "linkedinAccessToken": "LINKEDIN ACCESS TOKEN",
                "linkedinAccessTokenSecret": "LINKEDIN ACCESS TOKEN SECRET"
            }
        }
    }
}
public Social linkUserLinkedInAccount(String userName, String accessToken, String accessTokenSecret, String apiKey, String secretKey)throws App42Exception

Links the User LinkedIn access credentials to the App User account.

Parameters:

userName - Name of the user whose LinkedIn account to be linked
accessToken - LinkedIn Access Token that has been received after authorisation
accessTokenSecret - LinkedIn Access Token Secret that has been received after authorisation
apiKey - LinkedIn App API Key
secretKey - LinkedIn App Secret Key

Returns:

The Social object

Response: Social Object

For more details click Exception
String userName = "Nick";	
String accessToken = "LINKEDIN ACCESS TOKEN";
String accessTokenSecret = "LINKEDIN ACCESS TOKEN SECRET";					
String apiKey = "LINKEDIN API KEY";
String secretKey = "LINKEDIN SECRET KEY";
		
Social social = socialService.linkUserLinkedInAccount(userName, accessToken, accessTokenSecret, apiKey, secretKey);  /* returns the Twitter object. */ 
System.out.println("UserName" + social.getUserName());
System.out.println("LinkedinAccessToken" + social.getLinkedinAccessToken());
System.out.println("LinkedinAccessTokenSecret" + social.getLinkedinAccessTokenSecret());
System.out.println("LinkedinApiKey" + social.getLinkedinApiKey());
System.out.println("LinkedinSecretKey" + social.getLinkedinSecretKey());
String jsonResponse = social.toString(); /* returns the response in JSON format. (as shown below)*/ 
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "linkedinAccessToken": "LINKEDIN ACCESS TOKEN",
                "linkedinAccessTokenSecret": "LINKEDIN ACCESS TOKEN SECRET",
                "linkedinApiKey": "LINKEDIN API KEY",
                "linkedinSecretKey": "LINKEDIN SECRET KEY"
            }
        }
    }
}
  
public Social updateLinkedInStatus(String userName, String status) throws App42Exception

Updates the LinkedIn status of the specified user

Parameters:

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

Returns:

The Social object

Response: Social Object

Exception:

The method throws the following exception with the error code.
/*
3807 - NOT FOUND - LinkedIn App Credentials(ApiKey / SecretKey) does not exist. 
3808 - BAD REQUEST - The Access Credentials are invalid. 
3809 - NOT FOUND - LinkedIn User Access Credentials does not exist. Please use linkUserLinkedInAccount API to link the User LinkedIn account. 
*/ 	       
For more details click Exception
String userName = "Nick";
String status = "Reviewing LinkedIn APIs By Nick";	

Social social = socialService.updateLinkedInStatus(userName, status);  /* returns the Twitter object. */ 
System.out.println("userName is " + social.getUserName());
System.out.println("status is " + social.getStatus());
String jsonResponse = social.toString(); /* returns the response in JSON format. (as shown below)*/   
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "status": "Reviewing LinkedIn APIs By Nick"
            }
        }
    }
}        
public Social updateSocialStatusForAll(String userName, String status) throws App42Exception

Updates the status for all linked social accounts of the specified user.

Parameters:

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

Returns:

The Social object

Response: Social Object

Exception:

The method throws the following exception with the error code.
/*
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. 
*/ 		       
For more details click Exception
String userName = "Nick";
String status = "Reviewing Facebook/Twitter/LinkedIn APIs By Nick";
		
Social social = socialService.updateSocialStatusForAll(userName, status);  /* returns the Twitter object. */ 
System.out.println("userName is " + social.getUserName());   
System.out.println("requestToken is " + social.getStatus()); 
String jsonResponse = social.toString(); /* returns the response in JSON format. (as shown below)*/   
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "status": "Reviewing Facebook/Twitter/LinkedIn APIs By Nick"
            }
        }
    }
}