App42 Cloud API

iOS 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 allocate and initialize an instance of ServiceAPI. After initialization, apiKey and secretKey needs to be set which has been received while creating an application under App42.

ServiceAPI *serviceAPIObj = [[ServiceAPI alloc]init];
serviceAPIObj.apiKey = @"<API_KEY>";
serviceAPIObj.secretKey = @"<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 *socialService = [serviceAPIObj 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.

NSString *userName = @"Nick";	
NSString *accessToken = @"TWITTER ACCESS TOKEN";
NSString *accessTokenSecret = @"TWITTER ACCESS TOKEN SECRET";					
NSString *consumerKey = @"TWITTER CONSUMER KEY";
NSString *consumerSecret = @"TWITTER CONSUMER SECRET"; 
						
Social *social = [socialService linkUserTwitterAccount:userName consumerKey:consumerKey consumerSecret:consumerSecret accessToken:accessToken accessTokenSecret:accessTokenSecret]; /* Returns the Facebook object. */ 
NSLog(@"userName is = %@",social.userName);
NSLog(@"twitterConsumerKey is = %@",social.twitterConsumerKey);
NSLog(@"twitterConsumerSecret is = %@",social.twitterConsumerSecret);
NSLog(@"twitterAccessToken is = %@",social.twitterAccessToken);
NSLog(@"twitterAccessTokenSecret is = %@",social.twitterAccessTokenSecret);
NSString *jsonResponse = [social toString]; /* Returns the response in JSON format.*/
                            

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

NSString *userName = @"Nick";
NSString *status = @"Review All Social Api By Nick";
@try{
	Social *social = [socialService updateTwitterStatus:userName status:status]; /* Returns the Social object. */ 
} @catch(App42Exception *ex) {
	int appErrorCode = ex.appErrorCode;
	int httpErrorCode = ex.httpErrorCode;
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
}
	
	NSString *jsonText = ex.reason; /* 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.

-(Social*)linkUserFacebookAccount:(NSString *)userName accessToken:(NSString*)accessToken

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
		  
NSString *userName = @"Nick";                  
NSString *accessToken = @"FACEBOOK ACCESS TOKEN";

Social *social = [socialService linkUserFacebookAccount:userName accessToken:accessToken);  /* returns the Social object. */ 
NSLog(@"Username is %@",social.userName);
NSLog(@"FacebookAccessToken is %@",social.facebookAccessToken);
NSString *jsonResponse = [social toString]; /* Returns the response in JSON format.(as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "facebookAccessToken": "FACEBOOK ACCESS TOKEN"
            }
        }
    }
}  
                                        
-(Social*)linkUserFacebookAccount:(NSString *)userName appId:(NSString*)appId appSecret:(NSString*)appSecret accessToken:(NSString*)accessToken

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

NSString *userName = @"Nick"; 
NSString *accessToken = @"FACEBOOK ACCESS TOKEN";   
NSString *appId = @"FACEBOOK APP ID";
NSString *appSecret = @"FACEBOOK APP SECRET";                    

Social *social = [socialService linkUserFacebookAccount:userName appId:appId appSecret:appSecret accessToken:accessToken];  /* returns the Social object. */
NSLog(@"UserName is = %@",social.userName);
NSLog(@"FacebookAccessToken is = %@",social.facebookAccessToken);
NSLog(@"FacebookAppId is = %@",social.facebookAppId);
NSLog(@"FacebookAppSecret is = %@",social.facebookAppSecret); 
NSString *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"
            }
        }
    }
}   
                                            
-(Social *)updateFacebookStatus:(NSString *)userName status:(NSString*)status

Gets user details based on userName.

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.
/*
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
NSString *userName = @"Nick";
NSString *status = @"Reviewing Faecbook APIs By Nick";

Social *social = [socialService updateFacebookStatus:userName status:status];  /* returns the Social object. */ 
NSLog(@"userName is = %@",social.userName);
NSLog(@"status is = %@",social.status);
NSString *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"
            }
        }
    }
}  


                                            
-(Social *)linkUserTwitterAccount:(NSString *)userName accessToken:(NSString*)accessToken accessTokenSecret:(NSString*)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 authorisation
accessTokenSecret - Twitter Access Token Secret that has been received after authorisation

Returns:

The Social object

Response: Social Object

For more details click Exception
NSString *userName = @"Nick";
NSString *accessToken = @"TWITTER ACCESS TOKEN";
NSString *accessTokenSecret = @"TWITTER ACCESS TOKEN SECRET"; 
		
Social *social = [socialService linkUserTwitterAccount:userName accessToken:accessToken accessTokenSecret:accessTokenSecret);  /* returns the Social object. */ 
NSLog(@"UserName is = %@",social.userName);
NSLog(@"TwitterAccessToken is = %@",social.twitterAccessToken);
NSLog(@"TwitterAccessTokenSecret is = %@",social.twitterAccessTokenSecret);
NSString *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"
            }
        }
    }
}
-(Social *)linkUserTwitterAccount:(NSString *)userName consumerKey:(NSString*)consumerKey consumerSecret:(NSString*)consumerSecret accessToken:(NSString*)accessToken accessTokenSecret:(NSString*)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 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
NSString *userName = @"Nick";		
NSString *accessToken = @"TWITTER ACCESS TOKEN";
NSString *accessTokenSecret = @"TWITTER ACCESS TOKEN SECRET"; 				
NSString *consumerKey = @"TWITTER CONSUMER KEY";
NSString *consumerSecret = @"TWITTER CONSUMER SECRET";

Social *social = [socialService linkUserTwitterAccount:userName consumerKey:consumerKey consumerSecret:consumerSecret accessToken:accessToken accessTokenSecret:accessTokenSecret);  /* returns the Social object. */ 
NSLog(@"UserName is = %@",social.userName);
NSLog(@"TwitterAccessToken is = %@",social.twitterAccessToken);
NSLog(@"TwitterAccessTokenSecret is = %@",social.twitterAccessTokenSecret);
NSLog(@"TwitterConsumerKey is = %@",social.twitterConsumerKey);
NSLog(@"TwitterConsumerSecret is = %@",social.twitterConsumerSecret);
NSString *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"
            }
        }
    }
}
                                            
-(Social *)updateTwitterStatus:(NSString *)userName status:(NSString*)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: Twitter Object

Exception:

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

Social *social = [socialService updateTwitterStatus:userName status:status];  /* returns the Social object. */ 
NSLog(@"userName is = %@",social.userName);
NSLog(@"status is = %@",social.status);
NSString *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"
            }
        }
    }
}                                          
-(Social*)linkUserLinkedInAccount:(NSString *)userName accessToken:(NSString*)accessToken accessTokenSecret:(NSString*)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 authorisation
accessTokenSecret - LinkedIn Access Token Secret that has been received after authorisation

Returns:

The Social object

Response: Social Object

For more details click Exception
NSString *userName = @"Nick";		
NSString *accessToken = @"LINKEDIN ACCESS TOKEN";
NSString *accessTokenSecret = @"LINKEDIN ACCESS TOKEN SECRET"; 
				
Social *social = [socialService linkUserLinkedInAccount:userName accessToken: accessToken accessTokenSecret:accessTokenSecret]; /* returns the Social object. */ 
NSLog(@"UserName is = %@",social.userName);
NSLog(@"accessToken is = %@",social.accessToken);
NSLog(@"accessTokenSecret is = %@",social.accessTokenSecret);
NSString *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"
            }
        }
    }
}  
-(Social*)linkUserLinkedInAccount:(NSString *)userName accessToken:(NSString*)accessToken accessTokenSecret:(NSString*)accessTokenSecret apiKey:(NSString*)apiKey secretKey:(NSString*)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 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
NSString *userName = @"Nick";	
NSString *accessToken = @"LINKEDIN ACCESS TOKEN";
NSString *accessTokenSecret = @"LINKEDIN ACCESS TOKEN SECRET";					
NSString *apiKey = @"LINKEDIN API KEY";
NSString *secretKey = @"LINKEDIN SECRET KEY";

Social *social = [socialService linkUserTwitterAccount:userName accessToken:accessToken accessTokenSecret:accessTokenSecret apiKey:apiKey secretKey:secretKey];  /* returns the Twitter object. */ 
NSLog(@"userName is  %@" , social.userName);
NSLog(@"linkedinAccessToken is   %@" ,  social.linkedinAccessToken);
NSLog(@"linkedinAccessTokenSecret is  %@" , social.linkedinAccessTokenSecret);
NSLog(@"linkedinApiKey is   %@" ,  social.linkedinApiKey);
NSLog(@"linkedinSecretKey is  %@" , social.linkedinSecretKey);
NSString *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",
            }
        }
    }
} 
-(Social*)updateLinkedInStatus:(NSString *)userName status:(NSString*)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:

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
NSString *userName = @"Nick";
NSString *status = @"Reviewing LinkedIn APIs By Nick";	

Social *social = [socialService updateLinkedInStatus:userName status:status];  /* returns the Twitter object. */ 
NSLog(@"userName is  %@" , social.userName);
NSLog(@"albumName is   %@" ,  social.status);

NSString *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"
            }
        }
    }
}          
-(Social*)updateSocialStatusForAll:(NSString *)userName status:(NSString*)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:

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
NSString *userName = @"Nick";
NSString *status = @"Reviewing Facebook/Twitter/LinkedIn APIs By Nick";

Social *social = [socialService updateSocialStatusForAll:userName status:status];  /* returns the Twitter object. */ 
NSLog(@"userName is   %@" , social.userName);
NSLog(@"status is   %@" ,  social.status);
NSString *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"
            }
        }
    }
}