App42 Cloud API

PHP 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 = 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 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 Social 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->linkUserTwitterAccount($userName,$accessToken,$accessTokenSecret,$consumerKey,$consumerSecret);  /* returns the Social object. */
print_r("userName is " . $social->getUserName()); 
print_r("twitterAccessToken" . $social->getTwitterAccessToken()); 
print_r("twitterAccessTokenSecret" .  $social->getTwitterAccessTokenSecret());
print_r("twitterConsumerKey" . $social->getTwitterConsumerKey()); 
print_r("twitterConsumerSecret" .  $social->getTwitterConsumerSecret());
$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 creating a user with username which is already in database, the function will throw the Exception with message as "Not Found" and the appErrorCode as "3800" and the details as "Twitter App Credentials(ConsumerKey/ConsumerSecret/CallbackURL) does not exist".

try{
	$social = $socialService->updateTwitterStatus($userName,$status);
} catch(App42Exception $ex) {
	$appErrorCode = $ex->getAppErrorCode();
	$httpErrorCode = $ex->getHttpErrorCode();
	if($appErrorCode == 3800)
{
    // Handle here for Not Found (Twitter App Credentials(ConsumerKey/ConsumerSecret/CallbackURL) 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.)
}
  elsif(appErrorCode == 1401){
    //handle here for Client is not authorized
}
  else(appErrorCode == 1500){
   //handle here for Internal Server Error
}
	$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 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.

function linkUserFacebookAccount($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 authorisation

Returns:

The Social object

Response: Social Object

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

$social = $socialService->linkUserFacebookAccount($userName,$facebookAccessToken);  /* returns the Facebook object. */ 
print_r("userName is" . social->getUserName());
print_r("facebookAccessToken is" . social->getFacebookAccessToken());
$jsonResponse = $social->toString(); /* returns the response in JSON format. (as shown below)*/
                            
{
    "app42": {
        "response": {
            "success": true,
            "social": {
                "userName": "Nick",
                "facebookAccessToken": "FACEBOOK ACCESS TOKEN"
            }
        }
    }
}    

                                            
function linkUserFacebookAccount($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 authorisation
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->linkUserFacebookAccount($userName,$facebookAccessToken, $facebookAppId, $facebookAppSecret);  /* returns the Facebook object. */ 
print_r("userName is" . social->getUserName());
print_r("facebookAccessToken is" . social->getFacebookAccessToken());
print_r("facebookAppId is" . social->getFacebookAppSecret());
print_r("facebookAppSecret is" . social->getFacebookAppSecret());
$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"
				
            }
        }
    }
} 
                                            
function updateFacebookStatus($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:

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
						
$userName = "Nick";
$status = "Reviewing Twitter APIs By Nick";	
					
$social = $socialService->updateFacebookStatus($userName, $status);  /* returns the Facebook object. */ 
print_r("userName is" . social->getUserName());
print_r("facebookAppId is" . social->getFacebookAppSecret());
print_r("facebookAppSecret is" . social->getFacebookAppSecret());
print_r("facebookAccessToken is" . social->getFacebookAccessToken());
$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"
            }
        }
    }
}  

                                            
function linkUserTwitterAccount($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 authorisation
accessTokenSecret - Twitter Access Token Secret that has been received after authorisation

Returns:

The Social object

Response: Social Object

For more details click Exception
$userName = "Nick";						
$twitterAccessToken = "SD23435FF-m67CV2QqqizC6tKwS88R8K7YxTts54HPmUv4EfJC";
$twitterAccessTokenSecret = "DEFThh67kJdQAOS3zSBqn8SqjkRpgw8oJJZKV9vg";
						
$social = $socialService->linkUserTwitterAccount($userName,$twitterAccessToken,$twitterAccessTokenSecret);  /* returns the Twitter object. */ 
print_r("userName is" . $social->getUserName());
print_r("twitterAccessToken is" . $social->getTwitterAccessToken());
print_r("twitterAccessTokenSecret is" . $social->getTwitterAccessTokenSecret());
$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"
            }
        }
    }
}                                           
function linkUserTwitterAccount($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 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
$userName = "Nick";	
$twitterAccessToken = "SD23435FF-m67CV2QqqizC6tKwS88R8K7YxTts54HPmUv4EfJC";
$twitterAccessTokenSecret = "DEFThh67kJdQAOS3zSBqn8SqjkRpgw8oJJZKV9vg";					
$twitterConsumerKey = "7lFvyAd515aKrFWrtYU";
$twitterConsumerSecret = "uFQ4QBr1fxcTthcB7bE5yvnaqDF567UJddRk8vNs";

						
$social = $socialService->linkUserTwitterAccount($userName,$twitterAccessToken,$twitterAccessTokenSecret,$twitterConsumerKey,$twitterConsumerSecret,);  /* returns the Twitter object. */ 
print_r("userName is" . $social->getUserName());
print_r("twitterAccessToken is" . $social->getTwitterAccessToken());
print_r("twitterAccessTokenSecret is" . $social->getTwitterAccessTokenSecret());
print_r("twitterConsumerKey is" . $social->getTwitterConsumerKey());
print_r("twitterConsumerSecret is" . $social->getTwitterConsumerSecret());
$jsonResponse = $social->toString(); /* 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"
                
            }
        }
    }
}                                         
function updateStatus($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:

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. 
*/ 		  
        
For more details click Exception
						
$social = $socialService->updateTwitterStatus($userName, $status);  /* returns the Twitter object. */ 
print_r("userName is" . $social->getUserName());
print_r("twitterConsumerKey is" . $social->getTwitterConsumerKey());
print_r("twitterConsumerSecret is" . $social->getTwitterConsumerSecret());
print_r("twitterAccessToken is" . $social->getTwitterAccessToken());
print_r("twitterAccessTokenSecret is" . $social->getTwitterAccessTokenSecret());
response = $social.response(); 
$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"
            }
        }
    }
}  
                                            
function linkUserLinkedInAccount($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 authorisation
accessTokenSecret - LinkedIn Access Token Secret that has been received after authorisation

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->linkUserLinkedInAccount($userName,$accessToken,$accessTokenSecret);  /* returns the Twitter object. */ 
print_r("userName is" . $social->getUserName());
print_r("linkedinAccessToken is" . $social->linkedinAccessToken());
print_r("linkedinAccessTokenSecret is" . $social->linkedinAccessTokenSecret());
$response = $social->response(); 
$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"
            }
        }
    }
}
  
function linkUserLinkedInAccount($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 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
$userName = "Nick";	
$accessToken = "7a7493f4-e3dd-4ab3-8014-efea40518d3d";
$accessTokenSecret = "35c0745f-40d9-4889-9f37-6af7571e4249";					
$apiKey = "bua6eo3pq5g3";
$secretKey = "zBhKq5q7ruHcgH6l";
						
$social = $socialService->linkUserLinkedInAccount($userName,$accessToken,$accessTokenSecret,$apiKey,$secretKey);  /* returns the Twitter object. */ 
print_r("userName is" . $social->getUserName());
print_r("linkedinAccessToken is" . $social->linkedinAccessToken());
print_r("linkedinAccessTokenSecret is" . $social->linkedinAccessTokenSecret());
print_r("linkedinApiKey is" . $social->getLinkedinApiKey());
print_r("linkedinSecretKey is" . $social->getLinkedinSecretKey());
$response = $social->response(); 
$jsonResponse = $social->toString(); /* 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"
                
            }
        }
    }
}
  
function updateLinkedInStatus($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->updateLinkedInStatus($userName, $apiKey,$secretKey,$accessToken,$accessTokenSecret);  /* returns the Twitter object. */ 
print_r("userName is" . $social->getUserName());
print_r("linkedinApiKey is" . $social->getLinkedinApiKey());
print_r("linkedinSecretKey is" . $social->getLinkedinSecretKey());
print_r("linkedinAccessToken is" . $social->linkedinAccessToken());
print_r("linkedinAccessTokenSecret is" . $social->linkedinAccessTokenSecret());
response = $social.response(); 
$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"
            }
        }
    }
}  
                                            
function updateSocialStatusForAll($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->updateSocialStatusForAll($userName, $status);  /* returns the Twitter object. */ 
print_r("userName is" . $social->getUserName());
print_r("twitterConsumerKey is" . $social->getTwitterConsumerKey());
print_r("twitterConsumerSecret is" . $social->getTwitterConsumerSecret());
print_r("twitterAccessToken is" . $social->getTwitterAccessToken());
print_r("twitterAccessTokenSecret is" . $social->getTwitterAccessTokenSecret());
print_r("userName is" . social->getUserName());
print_r("facebookAppId is" . social->getFacebookAppSecret());
print_r("facebookAppSecret is" . social->getFacebookAppSecret());
print_r("facebookAccessToken is" . social->getFacebookAccessToken());
print_r("userName is" . $social->getUserName());
print_r("linkedinApiKey is" . $social->getLinkedinApiKey());
print_r("linkedinSecretKey is" . $social->getLinkedinSecretKey());
print_r("linkedinAccessToken is" . $social->linkedinAccessToken());
print_r("linkedinAccessTokenSecret is" . $social->linkedinAccessTokenSecret());
$response = $social->response(); 
$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"
            }
        }
    }
}