Social API - Consists of Facebook , Twitter And LinkedIn
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 SocialService, buildSocialService() 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,accessToken,accessTokenSecret,consumerKey,consumerSecret); /* returns the Social object. */
System.out.println("userName is " + social.getUserName());
System.out.println("twitterAccessToken is " + social.getTwitterAccessToken());
System.out.println("twitterAccessTokenSecret is " + social.getTwitterAccessTokenSecret());
System.out.println("twitterConsumerKey is " + social.getTwitterConsumerKey());
System.out.println("twitterConsumerSecret is " + social.getTwitterConsumerSecret());
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 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.
Links the User Facebook access credentials to the App User account.
Parameters:
Returns:
Response: Social Object
String userName = "Nick";
String accessToken = "FACEBOOK ACCESS TOKEN";
Social social = socialService.linkUserFacebookAccount(userName, accessToken); /* returns the Social object. */
System.out.println("userName is " + social.getUserName());
System.out.println("facebookAccessToken is " + 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"
}
}
}
}
Links the User Facebook access credentials to the App User account.
Parameters:
Returns:
Response: Social Object
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 Social object. */
System.out.println("userName is " + social.getUserName());
System.out.println("facebookAccessToken is " + social.getFacebookAccessToken());
System.out.println("facebookAppId is " + social.getFacebookAppId());
System.out.println("facebookAppSecret is " + 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",
}
}
}
}
Updates the Facebook status of the specified user.
Parameters:
Returns:
Response: Social Object
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. */
String userName = "Nick";
String status = "Reviewing Faecbook APIs By Nick";
Social social = socialService.updateFacebookStatus(userName, status); /* returns the Social 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"
}
}
}
}
Links the User Twitter access credentials to the App User account.
Parameters:
Returns:
Response: Social Object
String userName = "Nick";
String accessToken = "TWITTER ACCESS TOKEN";
String accessTokenSecret = "TWITTER ACCESS TOKEN SECRET";
Social social = socialService.linkUserTwitterAccount(userName,accessToken,accessTokenSecret); /* returns the Social object. */
System.out.println("userName is " + social.getUserName());
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)*/
{
"app42": {
"response": {
"success": true,
"social": {
"userName": "Nick",
"twitterAccessToken": "TWITTER ACCESS TOKEN",
"twitterAccessTokenSecret": "TWITTER ACCESS TOKEN SECRET"
}
}
}
}
Links the User Twitter access credentials to the App User account.
Parameters:
Returns:
Response: Social 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,accessToken,accessTokenSecret,consumerKey,consumerSecret); /* returns the Social object. */
System.out.println("userName is " + social.getUserName());
System.out.println("twitterAccessToken is " + social.getTwitterAccessToken());
System.out.println("twitterAccessTokenSecret is " + social.getTwitterAccessTokenSecret());
System.out.println("twitterConsumerKey is " + social.getTwitterConsumerKey());
System.out.println("twitterConsumerSecret is " + 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",
}
}
}
}
Updates the Twitter status of the specified user.
Parameters:
Returns:
Response: Social Object
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>. */
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"
}
}
}
}
Links the User LinkedIn access credentials to the App User account.
Parameters:
Returns:
Response: Social Object
String userName = "Nick";
String accessToken = "LINKEDIN ACCESS TOKEN";
String accessTokenSecret = "LINKEDIN ACCESS TOKEN SECRET";
Social social = socialService.linkUserLinkedInAccount(userName, accessToken, accessTokenSecret); /* returns the Social object. */
System.out.println("userName is " + social.getUserName());
System.out.println("linkedinAccessToken is " + social.getLinkedinAccessToken());
System.out.println("linkedinAccessTokenSecret is " + 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"
}
}
}
}
Links the User LinkedIn access credentials to the App User account.
Parameters:
Returns:
Response: Social Object
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 Social object. */
System.out.println("userName is " + social.getUserName());
System.out.println("linkedinAccessToken is " + social.getLinkedinAccessToken());
System.out.println("linkedinAccessTokenSecret is " + 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",
}
}
}
}
Updates the LinkedIn status of the specified user
Parameters:
Returns:
Response: Social Object
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. */
String userName = "Nick";
String status = "Reviewing LinkedIn APIs By Nick";
Social social = socialService.updateLinkedInStatus(userName, status); /* returns the Social 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"
}
}
}
}
Updates the status for all linked social accounts of the specified user.
Parameters:
Returns:
Response: Social Object
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. */
String userName = "Nick";
String status = "Reviewing Facebook/Twitter/LinkedIn APIs By Nick";
Social social = socialService.updateSocialStatusForAll(userName, status); /* returns the Social 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 Facebook/Twitter/LinkedIn APIs By Nick"
}
}
}
}