Pages

Showing posts with label Social Media. Show all posts
Showing posts with label Social Media. Show all posts

Tuesday, May 31, 2011

Company and Jobs - LinkedIn API

Now we can get company & job information available in LinkedIn using its API.This might help to show up the company & job deatils in applications.View .

You can check the below URL's by using a simple java program

Links to get company information in combination with LinkedIn data
1. To get the company information by giving the company domainhttp://api.linkedin.com/v1/companies?email-domain=kyyba.com
Output :



586336
Kyyba Inc


2. To get the company information by giving the company id
http://api.linkedin.com/v1/companies/586336:(id,name,description,industry,logo-url)

output :



586336
KYYBA Inc
Kyyba, Inc. is a Global provider of strategic staffing and managed services for the Information Technology and Engineering Clients
Kyyba service lines provide customers the following services:
Product and Software Development Services
Engineering and Design Services
Staff Augmentation Services
Outsourcing Services

Staffing and Recruiting
http://media.linkedin.com/mpr/mpr/p/2/000/050/2e0/322206a.png


3. To get the companies around the given area [us:84] http://api.linkedin.com/v1/company-search:(companies,facets)?facet=location,us:84 Output :






1028
Oracle

.
.
.



location
Location


us:0
United States
596338
false

.
.
.





4. To get company in which the token is createdhttp://api.linkedin.com/v1/people/~/following/companies

Output :





96307
Vision Tech Solutions


5. To get company to follow by the current userhttp://api.linkedin.com/v1/people/~/suggestions/to-follow/companies
I didn’t get any output data .

Links to get LinkedIn's jobs by company, industry and more to display relevant jobs to the users.
1. To get some job information in LinkedIn for the user
http://api.linkedin.com/v1/people/~/suggestions/job-suggestions
Output :






1641017

1333802

1441
Google


5EyneQPD-C
David
S.
test at Test Advantage

This position is based in Bangalore, India.
The area: Google.com EngineeringGoogle.com Engineering makes Google's services fast and reliable for hundreds of millions of users. Described as "software engineering for adrenaline junkies", the team combines software development, networking, and systems administration expertise to build and run massively distributed, fault-tolerant software system

Bangalore

.
.

50


2. To get some job information exsisiting in given area [US:84]http://api.linkedin.com/v1/job-search:(jobs,facets)?facet=location,us:84
Output :






1653582

1231
Symantec

Best in Industry

YRNg4JA8HX
Shyam Sundar
V.
Principal Recruiter at Symantec

 Symantec R&D in Pune has Senior Principal Software Engineer positions open. Interested and suitable candidates can apply. Role Details: Research and drive the adoption of new technologies to enhance existing product functionality • Provide technical vision and leadership necessary to grow the technical proficiency of the development teams• Mentor development teams in good architecture and des
Pune, Maharashtra

.
.

3. To get the particular job information by giving the JobId [jobid=1653560]
http://api.linkedin.com/v1/jobs/1452577:(id,company:(name),position:(title))
Output :




1653560

Tata Consultancy Services


Siebel Architect- Performance Management


4. To get some job bookmarcks
http://api.linkedin.com/v1/people/~/job-bookmarks

I didn’t get any output data .

Simple Java Program using LinkedIn API

The below program will helps you to fetch & view linkedIn data in a short time.

Follow this link to download the jars & to get token, secret to work with LinkedIn API

Simple Java Program. To get the LinkedIn details about the current user [Who created the token & secret key]


public static void main(String[] args) {

String linkedinKey = "C2E7PG.."; //Your LinkedIn key
String linkedinSecret = "9hyC6.. ";//Your LinkedIn Secret
OAuthConsumer consumer = new DefaultOAuthConsumer( linkedinKey,linkedinSecret);

OAuthProvider provider = new DefaultOAuthProvider("https://api.linkedin.com/uas/oauth/requestToken",
"https://api.linkedin.com/uas/oauth/accessToken",
"https://api.linkedin.com/uas/oauth/authorize");

System.out.println("Fetching request token from LinkedIn...");
String authUrl;
try {
authUrl = provider.retrieveRequestToken(consumer, OAuth.OUT_OF_BAND);
System.out.println("Check the below link and grant this app authorization -You will get Pin Number.Copy it\n" + authUrl );
System.out.println("Enter the PIN code and hit ENTER when you're done:");
} catch (OAuthMessageSignerException e1) {
e1.printStackTrace();
} catch (OAuthNotAuthorizedException e1) {
e1.printStackTrace();
} catch (OAuthExpectationFailedException e1) {
e1.printStackTrace();
} catch (OAuthCommunicationException e1) {
e1.printStackTrace();
}
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String pin;
try {
pin = br.readLine();
System.out.println("Fetching access token from LinkedIn...");
provider.retrieveAccessToken(consumer, pin);
System.out.println("Access token: " + consumer.getToken());
System.out.println("Token secret: " + consumer.getTokenSecret());
URL url = new URL("http://api.linkedin.com/v1/people/~:(id,first-name,last-name,picture-url,headline)");

HttpURLConnection request = (HttpURLConnection) url.openConnection();
consumer.sign(request);
request.connect();
System.out.println("Sending request to LinkedIn...");
String responseBody = convertStreamToString(request.getInputStream());
System.out.println("Response: " + request.getResponseCode() + " "
+ request.getResponseMessage() + "\n" + responseBody);

} catch (OAuthMessageSignerException e) {
e.printStackTrace();
} catch (OAuthNotAuthorizedException e) {
e.printStackTrace();
} catch (OAuthExpectationFailedException e) {
e.printStackTrace();
} catch (OAuthCommunicationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String convertStreamToString(InputStream is) {

BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
}


Output

Fetching request token from LinkedIn...
Check the below link and grant this app authorization -You will get Pin Number.Copy it
https://api.linkedin.com/uas/oauth/authorize?oauth_token=dcb835667-a5d7-4e95-91f9-fde4b9b47e3a
Enter the PIN code and hit ENTER when you're done:
59278
Fetching access token from LinkedIn...
Access token: f0f94b3d-50b9-4549-bd96-5d1ea3ba7a9c
Token secret: f2b13c99-f206-4612-bf9e-2afc1387bc1a
Sending request to LinkedIn...
Response: 200 OK



GtYKzPiNkX
Sundari Shree
Gunasekaran
Software Engineer at Vision Tech Solutions


Note: By passing the different URL’s as parameter You can check all the available information in LinkedIn .

URL url = new URL("http://api.linkedin.com/v1/people/~:(id,first-name,last-name,picture-url,headline)");

This URL is to get about the people information.

Wednesday, July 7, 2010

Facebook API

FaceBook API lets you create and manage your own ads on Facebook programmatically

DownLoad Facebook jar
To work in JAVA Download - facebook-java-api-3.0.2-bin.zip

Inlcuded the jar in the class path and try to access the class in the jar

IDE
Eclipse - Version: 3.4.0


Get the API key & Application Secret

To start your work with Facebook API, You need to get the
API key & Application Key.

You need to get register your applications in this page http://www.facebook.com/developers/apps.php using Facebook account.

Necessary fields to be entered as follows
In Basic - Include the developers name .Who will be involving in developing the application.
In Canvas –Give the callback url of your application


We can start coding the application now.

Create the Twitter object & get the request token by passing the application Consumer key & secret.

To get the user client

FacebookJsonRestClient class is used for getting user client returns the object in JSON format.

FacebookJsonRestClient userClient =getUserClientsession);
public static FacebookJsonRestClient.getUserClient(HttpSession session) {
return (FacebookJsonRestClient)session.getAttribute(FACEBOOK_USER_CLIENT);
}


User session doesn't have a Facebook API client setup yet.

Pass the API key & Application secret to get the valid userclient
And store it in a session.

userClient = new FacebookJsonRestClient(api_key, secret);
session.setAttribute(FACEBOOK_USER_CLIENT, userClient);


Pass the Facebook url with your api key & required permission redirect the call.

You can check the permission available in Facebook .

facebook = new FacebookWebappHelper(req, res, api_key, secret);
nextPage = req.getRequestURI();
nextPage = nextPage.substring(nextPage.indexOf("/", 1) + 1);
//cut out the first /, the context path and the 2nd /
System.out.println(nextPage);
boolean redirectOccurred = facebook.requireLogin(nextPage);
if(redirectOccurred){
res.sendRedirect("http://www.facebook.com/login.php?api_key=dbfc65d0e72f5c103gg0gfgd8c5&connect_display=popup&v=1.0&next=http://www.facebook.com/connect/login_success.html&cancel_url=http://www.facebook.com/connect/login_failure.html&fbconnect=true&return_session=true&session_key_only=true&req_perms=read_stream,publish_stream,offline_access,sms,email,user_location");
return;
}

After execution of the above code.It request you enter the Facebook username & password.

Get the auth_token

String authToken=request.getParameter("auth_token");

By passing this authToken to the client you can start working on the functionalities like getting friends ,knowing user details etc.,

You can check the functionalities available in the FacebookJsonRestClient in this link
http://developers.facebook.com/docs/reference/rest/

Functions
To know the current user id

Long facebookUserID = userClient.users_getLoggedInUser();

To get friends Id’s

JSONArray arrayObj = (JSONArray)userClient.friends_get();

Get the id’s from Array & store it in a list

List userIds = new ArrayList();
for(int i=0;i try {
userIds.add((arrayObj.getString(i));
} catch (JSONException e) {
e.printStackTrace();
}
}

Set the necessary fields in the ProfileField,that you need from a
User.



EnumSet fields = EnumSet.of ( com.google.code.facebookapi.ProfileField.NAME, com.google.code.facebookapi.ProfileField.PIC, com.google.code.facebookapi.ProfileField.CURRENT_LOCATION, com.google.code.facebookapi.ProfileField.FIRST_NAME, com.google.code.facebookapi.ProfileField.LAST_NAME);

To get the user details
  	                                            

JSONArray userArray = null;
try {
userArray = client.users_getInfo(userIds, fields);
} catch (FacebookException e1) {
e1.printStackTrace();
}
for(int i=0;i< userArray.length();i++){
try {
for (int j = 0; j < userArray.length(); j++) {
JSONObject obj = userArray.getJSONObject(j);
System.out.println("User Id"+obj.getString("uid"));
System.out.println("Pic url "+obj.getString("pic"));
System.out.println("Name"+obj.getString("first_name")
+" "+obj.getString "last_name"));
}
} catch (JSONException e) {
e.printStackTrace();}
}


To update the status of the current user
Check whether the user having the permissions & than try the functions

if (userClient.users_hasAppPermission(Permission.STATUS_UPDATE)){
userClient.users_setStatus("Status-Developing Facebook apps in Java!", false);
}

To Publish the stream for the current user

if(userClient.users_hasAppPermission(Permission.PUBLISH_STREAM)){
userClient.stream_publish("Stream-Publish-Wall written using Facebook API !", null, null, null, null);
}


To post the link to single /Group of user

userClient.links_post(Long.parseLong("Give the UserID"), "www.kyyba.com", "IT Recruitment");