App42 Cloud API

Windows Phone 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 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 Windows Phone API's work in an asynchronous mode that means the response will not be available immediately and all the API methods would not return any value and have return type as void. The response will be returned in callback methods which the caller will provide to the calling method.
As mentioned above that the response will be returned in callback methods, every API method is taking instance of App42Callback (as the last parameter) which will have the implementation of 2 methods: OnSuccess & OnException.(as shown below)

public class CallBack : App42Callback
{
public override void OnSuccess(Object obj)
{
Social social = (Social) obj;
//Do whatever you want with the user object
}
public override void OnException(App42Exception e)
{
//Do whatever you want with the exception
}
}

The callback methods will return the response in the form of Object which will have to be type cast to the object domain object (e.g. App42Response / Facebook / Twitter/ LinkedIn in this case) The Domain object 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.

public override void OnSuccess(Object obj)
{
Social social = (Social) obj; 
Console.WriteLine("UserName" + social.GetUserName());
Console.WriteLine("Status" + social.GetStatus());
Console.WriteLine("TwitterConsumerKey" + social.GetTwitterConsumerKey());
Console.WriteLine("TwitterConsumerSecret" + social.GetTwitterConsumerSecret());
Console.WriteLine("TwitterAccessToken" + social.GetTwitterAccessToken());
Console.WriteLine("TwitterAccessTokenSecret" + social.GetTwitterAccessTokenSecret());
Console.WriteLine("FacebookAppId" + social.GetFacebookAppId());
Console.WriteLine("FacebookAppSecret" + social.GetFacebookAppSecret());
Console.WriteLine("FacebookAccessToken" + social.GetFacebookAccessToken());
Console.WriteLine("LinkedinApiKey" + social.GetLinkedinApiKey());
Console.WriteLine("LinkedinSecretKey" + social.GetLinkedinSecretKey());
Console.WriteLine("LinkedinAccessToken" + social.GetLinkedinAccessToken());
Console.WriteLine("LinkedinAccessTokenSecret" + social.GetLinkedinAccessTokenSecret());
String 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".

public override void OnException(App42Exception ex)
{
int appErrorCode = ex.GetAppErrorCode();
int httpErrorCode = ex.GetHttpErrorCode();
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.

public void LinkUserFacebookAccount(String userName,String accessToken, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

The Social object

Response: Social Object

For more details click Exception
String userName = "Nick";    
String accessToken = "FACEBOOK ACCESS TOKEN";  

socialService.LinkUserFacebookAccount(userName,accessToken,requestCallback);  /* returns the Facebook object. */ 
OnSuccess(Object obj){
Social social = (Social) obj;
Console.WriteLine("UserName" + social.GetUserName());
Console.WriteLine("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 void LinkUserFacebookAccount(String userName,String accessToken,String appId, String appSecret, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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


socialService.LinkUserFacebookAccount(userName,accessToken,appId, appSecret,requestCallback);  /* returns the Facebook object. */ 
OnSuccess(Object obj){
Social social = (Social) obj;
Console.WriteLine("UserName" + social.GetUserName());
Console.WriteLine("FacebookAccessToken" + social.GetFacebookAccessToken());
Console.WriteLine("FacebookAppId" + social.GetFacebookAppId());
Console.WriteLine("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 void UpdateFacebookStatus(String userName, String status,App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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
String userName = "Nick";
String status = "Reviewing Faecbook APIs By Nick";

socialService.UpdateFacebookStatus(userName, status ,requestCallback);  /* returns the Facebook object. */ 
OnSuccess(Object obj){
Social social = (Social) obj;
Console.WriteLine("UserName" + social.GetUserName());
Console.WriteLine("FacebookAppId" + 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 void GetFacebookFriendsFromLinkUser(String userName,App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

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
String userName = "Nick";

socialService.GetFacebookFriendsFromLinkUser(userName ,requestCallback);  /* returns the Facebook object. */ 
OnSuccess(Object obj){
	Social social = (Social) obj;
	Console.WriteLine("userName is " + social.GetUserName());
	IList<Social.Friends> friendsList = social.GetFriendList();
	for(int i = 0; i < friendsList.Count(); i++)
	{
		Console.WriteLine("Friend Name is " + friendsList[0].GetName());
		Console.WriteLine("Friend Id is " + friendsList[0].GetId());
	}
	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 void GetFacebookFriendsFromAccessToken(String accessToken, App42Callback requestCallback)

Updates the Facebook status of the specified user.

Parameters:

accessToken - Facebook Access Token that has been received after authorization
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

Returns:

Social object

Response: Social Object

Exception:

This method throws following exception.
/*		   
3805 - BAD REQUEST - The Facebook Access Credentials are invalid. 
*/ 		        
For more details click Exception
String accessToken = "Nick";

socialService.GetFacebookFriendsFromAccessToken(accessToken ,requestCallback);  /* returns the Facebook object. */ 
OnSuccess(Object obj){
	Social social = (Social) obj;
	Console.WriteLine("userName is " + social.GetUserName());
	IList<Social.Friends> friendsList = social.GetFriendList();
	for(int i = 0; i < friendsList.Count(); i++)
	{
		Console.WriteLine("Friend Name is " + friendsList[0].GetName());
		Console.WriteLine("Friend Id is " + friendsList[0].GetId());
	}
	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 void LinkUserTwitterAccount(String userName,String accessToken, String accessTokenSecret, App42Callback requestCallback)

Links the User Facebook 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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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

socialService.LinkUserTwiiterAccount(userName,twitterAccessToken,twitterAccessTokenSecret,requestCallback);  /* returns the Twitter object. */ 
OnSuccess(Object obj){
Social social = (Social) obj;
Console.WriteLine("UserName" + social.GetUserName());
Console.WriteLine("TwitterAccessToken" + social.GetTwitterAccessToken());
Console.WriteLine("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 void LinkUserTwitterAccount(String userName, String accessToken, String accessTokenSecret, String consumerKey, String consumerSecret,App42Callback requestCallback)

Links the User Facebook 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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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

socialService.LinkUserTwiiterAccount(userName,twitterAccessToken,twitterAccessTokenSecret,twitterConsumerKey,twitterConsumerSecret,requestCallback);  /* returns the Twitter object. */ 
OnSuccess(Object obj){
Social social = (Social) obj;
Console.WriteLine("UserName" + social.GetUserName());
Console.WriteLine("TwitterAccessToken" + social.GetTwitterAccessToken());
Console.WriteLine("TwitterAccessTokenSecret" + social.GetTwitterAccessTokenSecret());
Console.WriteLine("TwitterConsumerKey" + social.GetTwitterConsumerKey());
Console.WriteLine("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 void UpdateTwitterStatus(String userName, String status, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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." + <Exception Message> 
*/ 	       
For more details click Exception
String userName = "Nick";
String status = "Reviewing Twitter APIs By Nick";

socialService.UpdateTwitterStatus(userName, status,requestCallback);  /* returns the Facebook object. */ 
OnSuccess(Object obj){
Social social = (Social) obj;
Console.WriteLine("UserName" + social.GetUserName());
Console.WriteLine("Status" + 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 void LinkUserLinkedInAccount(String userName,String accessToken, String accessTokenSecret, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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

socialService.LinkUserLinkedInAccount(userName,accessToken,accessTokenSecret,requestCallback);  /* returns the LinkedIn object. */ 
OnSuccess(Object obj){
Social social = (Social) obj;
Console.WriteLine("UserName" + social.GetUserName());
Console.WriteLine("LinkedinAccessToken" + social.GetLinkedinAccessToken());
Console.WriteLine("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 void LinkUserLinkedInAccount(String userName, String accessToken, String accessTokenSecret, String apiKey, String secretKey,App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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


socialService.LinkUserLinkedInAccount(userName, apiKey,secretKey,accessToken,accessTokenSecret,requestCallback);  /* returns the LinkedIn object. */ 
OnSuccess(Object obj){
Social social = (Social) obj;
Console.WriteLine("UserName" + social.GetUserName());
Console.WriteLine("LinkedinAccessToken" + social.GetLinkedinAccessToken());
Console.WriteLine("LinkedinAccessTokenSecret" + social.GetLinkedinAccessTokenSecret());
Console.WriteLine("LinkedinApiKey" + social.GetLinkedinApiKey());
Console.WriteLine("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 void UpdateLinkedInStatus(String userName, String status, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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
String userName = "Nick";
String status = "Reviewing Twitter APIs By Nick";

socialService.UpdateLinkedInStatus(userName, status,requestCallback);  /* returns the Facebook object. */ 
OnSuccess(Object obj){
Social social = (Social) obj;
Console.WriteLine("UserName" + social.GetUserName());
Console.WriteLine("LinkedinApiKey" + 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 void UpdateSocialStatusForAll(String userName, String status, App42Callback requestCallback)

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
requestCallback - Callback instance that will have the implementation of OnSuccess & OnException of App42Callback.

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
String userName = "Nick";
String status = "Reviewing Twitter APIs By Nick";

socialService.UpdateSocialStatusForAll(userName, status,requestCallback);  /* returns the Facebook object. */ 
OnSuccess(Object obj){
Social social = (Social) obj;
Console.WriteLine("UserName" + social.GetUserName());
Console.WriteLine("Status" + 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"
            }
        }
    }
}