App42 Cloud API

Ruby Cloud SDK

Social

Social API consists of Facebook , Twitter And LinkedIn



Facebook - Integrates with Facebook to update the User Status.

Twitter - Integrates with Twitter to update the User Status.

LinkedIn - Integrates with LinkedIn to update the User Status.

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.

api = App42::ServiceAPI.new("<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 SocialService, BuildSocialService() method needs to be called.

							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 user 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.

userName = "Nick";	
accessToken = "TWITTER ACCESS TOKEN";
accessTokenSecret = "TWITTER ACCESS TOKEN SECRET";					
consumerKey = "TWITTER CONSUMER KEY";
consumerSecret = "TWITTER CONSUMER SECRET"; 

social = socialService.link_user_twitter_account(userName,accessToken,accessTokenSecret,consumerKey,consumerSecret);  /* returns the Facebook object. */ 
puts "userName is #{social.userName}";
puts "twitterAccessToken is #{social.twitterAccessToken}";
puts "twitterAccessTokenSecret is #{social.twitterAccessTokenSecret}";
puts "twitterConsumerKey is #{social.twitterConsumerKey}";
puts "twitterConsumerSecret is #{social.twitterConsumerSecret}";
jsonResponse = social.to_s(); /* 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/CallbackURL) does not exist".

begin
  social = socialService.update_twitter_status(userName, status);
rescue App42Exception => ex
  appErrorCode = ex.app_error_code;
  httpErrorCode = ex.http_error_code;

  if(appErrorCode == 3800)
    #Handle here for NOT FOUND (Twitter App Credentials(ConsumerKey/ConsumerSecret/CallbackURL) does not exist)

  elsif(appErrorCode == 3801)
    #Handle here for Bad Request (The request is Unauthorized with the provided credentials.)
	
 elsif(appErrorCode == 3802)
    #Handle here for NOT FOUND (Twitter User Access Credentials does not exist. Please use linkUserTwitterAccount API to link the User Twitter account.)
	
	elsif(appErrorCode == 3803)
    #Handle here for Bad Request (The Twitter Access Credentials are invalid.)
   
   elsif(appErrorCode == 1401)
    #handle here for Client is not authorized

  else(appErrorCode == 1500)
    #handle here for Internal Server Error
  end

  String jsonText = ex.getMessage(); /* returns the Exception text in JSON format. (as shown below)*/
end
{
    "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 Social 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 Social 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.

def link_user_facebook_account(userName,facebookAccessToken)

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 authorization

Returns:

The Social object

Response: Social Object

For more details click Exception
						
userName = "Nick";						
facebookAccessToken = "SD23435FF-m67CV2QqqizC6tKwS88R8K7YxTts54HPmUv4EfJC";

social = socialService.link_user_facebook_account(userName,facebookAccessToken);  /* returns the Facebook object. */ 
puts "userName is #{social.userName}";
puts "facebookAccessToken is #{social.facebookAccessToken}";
jsonResponse = social.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "facebookAccessToken": "FACEBOOK ACCESS TOKEN"
            }
        }
    }
}
def link_user_facebook_account_with_token(userName,accessToken,appId,appSecret)

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 authorization
appId - Facebook App Id appSecret - Facebook App Secret

Returns:

The Social object

Response: Social Object

For more details click Exception
userName = "Nick";
facebookAccessToken = "SD23435FF-m67CV2QqqizC6tKwS88R8K7YxTts54HPmUv4EfJC";						
facebookAppId = "7lFvyAd515aKrFWrtYU";
facebookAppSecret = "uFQ4QBr1fxcTthcB7bE5yvnaqDF567UJddRk8vNs";

social = socialService.link_user_facebook_account_with_token(userName,facebookAccessToken,facebookAppId, facebookAppSecret);  /* returns the Facebook object. */ 
puts "userName is #{social.userName}";
puts "facebookAccessToken is #{social.facebookAccessToken}";
puts "facebookAppId is #{social.facebookAppId}";
puts "facebookAppSecret is #{social.facebookAppSecret}";
jsonResponse = social.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "facebookAppId": "FACEBOOK APP ID",
                "facebookAppSecret": "FACEBOOK APP SECRET",
                "facebookAccessToken": "FACEBOOK ACCESS TOKEN"
            }
        }
    }
}
def update_facebook_status(userName,status)

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
userName = "Nick";
status = "Reviewing Twitter APIs By Nick";	
					
social = socialService.update_facebook_status(userName, status);  /* returns the Facebook object. */ 
puts "userName is #{social.userName}";
puts "facebookAppId is #{social.facebookAppId}";
puts "facebookAppSecret is #{social.facebookAppSecret}";
puts "facebookAccessToken is #{social.facebookAccessToken}";
jsonResponse = social.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "status": "Reviewing Faecbook APIs By Nick"
            }
        }
    }
}
def link_user_twitter_account(userName,accessToken,accessTokenSecret)

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 authorization
accessTokenSecret - Twitter Access Token Secret that has been received after authorization

Returns:

The Social object

Response: Social Object

For more details click Exception
userName = "Nick";						
twitterAccessToken = "SD23435FF-m67CV2QqqizC6tKwS88R8K7YxTts54HPmUv4EfJC";
twitterAccessTokenSecret = "DEFThh67kJdQAOS3zSBqn8SqjkRpgw8oJJZKV9vg";
						
social = socialService.link_user_twitter_account(userName,twitterAccessToken,twitterAccessTokenSecret);  /* returns the Twitter object. */ 
puts "userName is #{social.userName}";
puts "twitterAccessToken is #{social.twitterAccessToken}"; 
puts "twitterAccessTokenSecret is #{social.twitterAccessTokenSecret}"; 
jsonResponse = social.to_s(); /* 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"
            }
        }
    }
}
def link_user_twitter_account_with_token(userName,accessToken,accessTokenSecret,consumerKey,consumerSecret)

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 authorization
accessTokenSecret - Twitter Access Token Secret that has been received after authorization
consumerKey - Twitter App Consumer Key
consumerSecret - Twitter App Consumer Secret

Returns:

The Social object

Response: Social Object

For more details click Exception
userName = "Nick";
twitterAccessToken = "SD23435FF-m67CV2QqqizC6tKwS88R8K7YxTts54HPmUv4EfJC";
twitterAccessTokenSecret = "DEFThh67kJdQAOS3zSBqn8SqjkRpgw8oJJZKV9vg";						
twitterConsumerKey = "7lFvyAd515aKrFWrtYU";
twitterConsumerSecret = "uFQ4QBr1fxcTthcB7bE5yvnaqDF567UJddRk8vNs";
			
social = socialService.link_user_twitter_account_with_token(userName,,twitterAccessToken,twitterAccessTokenSecret,twitterConsumerKey,twitterConsumerSecret);  /* returns the Twitter object. */ 
puts "userName is #{social.userName}";
puts "twitterAccessToken is #{social.twitterAccessToken}"; 
puts "twitterAccessTokenSecret is #{social.twitterAccessTokenSecret}";
puts "twitterConsumerKey is #{social.twitterConsumerKey}";
puts "twitterConsumerSecret is #{social.twitterConsumerSecret}";
jsonResponse = social.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "twitterConsumerKey": "TWITTER CONSUMER KEY",
                "twitterConsumerSecret": "TWITTER CONSUMER SECRET",
                "twitterAccessToken": "TWITTER ACCESS TOKEN",
                "twitterAccessTokenSecret": "TWITTER ACCESS TOKEN SECRET"
            }
        }
    }
}
def update_twitter_status(userName,status)

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: Social 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. 
*/
For more details click Exception
social = socialService.update_twitter_status(userName, status);  /* returns the Twitter object. */ 
puts "userName is #{social.userName}";
puts "status is #{social.status}";
puts "twitterConsumerKey is #{social.twitterConsumerKey}";
puts "twitterConsumerSecret is #{social.twitterConsumerSecret}";
puts "twitterAccessToken is #{social.twitterAccessToken}";
puts "twitterAccessToken is #{social.twitterAccessTokenSecret}";
jsonResponse = social.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "status": "Reviewing Twitter APIs By Nick"
            }
        }
    }
}
def link_user_linkedIn_account(userName,accessToken,accessTokenSecret)

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 authorization
accessTokenSecret - LinkedIn Access Token Secret that has been received after authorization

Returns:

The Social object

Response: Social Object

For more details click Exception
userName = "Nick";						
accessToken = "7a7493f4-e3dd-4ab3-8014-efea40518d3d";
accessTokenSecret = "35c0745f-40d9-4889-9f37-6af7571e4249";
						
social = $socialService.link_user_linkedIn_account(userName,accessToken,accessTokenSecret);  /* returns the Twitter object. */ 
puts "userName is #{social.userName}";
puts "linkedinAccessToken is #{social.linkedinAccessToken}";
puts "linkedinAccessTokenSecret is #{social.linkedinAccessTokenSecret}";
response = social.response(); 
jsonResponse = social.to_s(); /* 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"
            }
        }
    }
}
def link_user_linkedIn_account_with_token(userName,accessToken,accessTokenSecret,apiKey,secretKey)

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 authorization
accessTokenSecret - LinkedIn Access Token Secret that has been received after authorization
apiKey - LinkedIn App API Key
secretKey - LinkedIn App Secret Key

Returns:

The Social object

Response: Social Object

For more details click Exception
userName = "Nick";	
accessToken = "7a7493f4-e3dd-4ab3-8014-efea40518d3d";
accessTokenSecret = "35c0745f-40d9-4889-9f37-6af7571e4249";						
apiKey = "bua6eo3pq5g3";
secretKey = "zBhKq5q7ruHcgH6l";
					
social = socialService.link_user_linkedIn_account_with_token(userName,accessToken,accessTokenSecret, apiKey,secretKey);  /* returns the Twitter object. */ 
puts "userName is #{social.userName}";
puts "linkedinAccessToken is #{social.linkedinAccessToken}";
puts "linkedinAccessTokenSecret is #{social.linkedinAccessTokenSecret}";
puts "linkedinApiKey is #{social.linkedinApiKey}";
puts "linkedinSecretKey is #{social.linkedinSecretKey}";
response = social.response(); 
jsonResponse = social.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "social": {  
                "userName": "Nick",
                "linkedinApiKey": "LINKEDIN API KEY",
                "linkedinSecretKey": "LINKEDIN SECRET KEY",
                "linkedinAccessToken": "LINKEDIN ACCESS TOKEN",
                "linkedinAccessTokenSecret": "LINKEDIN ACCESS TOKEN SECRET"
            }
        }
    }
}                                           
def update_linkedIn_status(userName,status)

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:

This method throws following exception.
/*
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
userName = "Nick";
status = "Reviewing Twitter APIs By Nick";

social = socialService.update_linkedIn_status(userName, apiKey,secretKey,accessToken,accessTokenSecret);  /* returns the Twitter object. */ 
puts"userName is #{social.userName}";
puts "linkedinApiKey is #{social.linkedinApiKey}";
puts "linkedinSecretKey is #{social.linkedinSecretKey}";
puts "linkedinAccessToken is #{social.linkedinAccessToken}";
puts "linkedinAccessTokenSecret is #{social.linkedinAccessTokenSecret}";
response = social.response(); 
jsonResponse = social.to_s(); /* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "status": "Reviewing LinkedIn APIs By Nick"
            }
        }
    }
}
def update_social_status_for_all(userName,status)

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:

This method throws following exception.
/*
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
userName = "Nick";
status = "Reviewing Twitter APIs By Nick";

social = socialService.update_social_status_for_all(userName, status);  /* returns the Twitter object. */ 
puts "userName is #{social.userName}";
puts "twitterConsumerKey is #{social.twitterConsumerKey}";
puts "twitterConsumerSecret is #{social.twitterConsumerSecret}";
puts "twitterAccessToken is #{social.twitterAccessToken}";
puts "twitterAccessToken is #{social.twitterAccessTokenSecret}";
puts "userName is #{social.userName}";
puts "facebookAppId is #{social.facebookAppId}";
puts "facebookAppSecret is #{social.facebookAppSecret}";
puts "facebookAccessToken is #{social.facebookAccessToken}";
puts "userName is #{social.userName}";
puts "linkedinApiKey is #{social.linkedinApiKey}";
puts "linkedinSecretKey is #{social.linkedinSecretKey}";
puts "linkedinAccessToken is #{social.linkedinAccessToken}";
puts "linkedinAccessTokenSecret is #{social.linkedinAccessTokenSecret}";
response = social.response(); 
jsonResponse = social.to_s();/* returns the response in JSON format. (as shown below)*/
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "status": "Reviewing Facebook/Twitter/LinkedIn APIs By Nick"
            }
        }
    }
}