Reputation: 3214
I searched lot and I can see some questions same as mine in StackOverflow too but didn't get answer.
I need to get user(google+ and facebook) messages whatever posted by him under his/her account and give it as xml response to a mobile app which is going to show user posts as better format/design - so here I need to fetch the posts from google+/facebook using the profile-id/username.
Eg: Like from twitter I can able to see status from
Is there any library or any particular way by which i can get it?
Thanks in Advance.
Upvotes: 0
Views: 631
Reputation: 8681
You can use the activities API for Google+. This is currently restricted to public posts but should be enough to get you started. The profile ID comes from a user's profile. There are other ways you can get this content as well, including the search API.
The documentation and simple examples from various languages can be found on the Google plus page (https://developers.google.com/+/api/latest/activities) and the following JavaScript example could be helpful for justing seeing how things work:
// globals used for auth, showing debugging
var debug = true;
var key = "your api key from https://code.google.com/apis/console";
function handleRequestIssue(request){
// For now, just show the error
console.log("Error, status:" + request.status + " / response:" + request.responseText);
}
function performXHR(URL){
var objReturn = "";
var request = new XMLHttpRequest();
request.open('GET', URL, false);
request.send(); // because of "false" above, will block until the request is done
// and status is available. Not recommended, however it works for simple cases.
if (request.status === 200) {
if (debug) console.log(request.responseText);
var objReturn = jQuery.parseJSON(request.responseText).items;
if (debug){
for (value in objReturn){
console.log(value);
}
}
}else{
handleRequestIssue(request);
}
return objReturn;
}
// Gets the activities for a profile
function getActivities(profileID){
var activities = null;
var URL = "https://www.googleapis.com/plus/v1/people/" + profileID + "/activities/public?alt=json&key=" + key;
activities = performXHR(URL);
console.log(activities.length);
return activities;
}
You can at this point see the activities in your debugger. You could always render the content as HTML inside a div or something.
function renderActsComments(activities, identifier, filter){
var renderMe = "";
console.log("activities retrieved: " + activities.length);
for (var i=0; i < activities.length; i++) {
var render = true;
console.log("trying to do something with an activity: " + i);
var activity = activities[i];
if (filter != null && filter.length > 0){
if (activity.crosspostSource.indexOf(filter) == -1){
render = false;
}
}
if (render == true){
renderMe += "<br/><div class=\"article\"><p>" + activity.title + "</p>";
console.log(activity.id);
// get comments
var comments = getCommentsForActivity(activity.id);
var left = true;
for (var j=0; j<comments.length; j++){
if (left){
left = false;
renderMe += "<br/><p class=\"speech\">" + comments[j].object.content + "</p>";
renderMe += "<a href=\"" + comments[j].actor.url + "\">" + comments[j].actor.displayName + "</a>";
renderMe += "<a href=\"" + comments[j].actor.image.url.replace(/\?.*/, "") + "\">";
renderMe += " <img border=0 src=\"" + comments[j].actor.image.url + "\"/></a>";
renderMe += "</p>";
}else{
renderMe += "<br/><p class=\"speechAlt\">" + comments[j].object.content + "</p>";
left = true;
renderMe += "<p class=\"profileAlt\">";
renderMe += "<a href=\"" + comments[j].actor.image.url.replace(/\?.*/, "") + "\">";
renderMe += "<img border=0 src=\"" + comments[j].actor.image.url + "\"/></a>";
renderMe += "<a href=\"" + comments[j].actor.url + "\"> " + comments[j].actor.displayName + "</a>";
renderMe += "</p>";
}
}
renderMe += "</div>";
}
}
console.log("I'm done");
document.getElementById(identifier).innerHTML = renderMe;
return renderMe;
}
Upvotes: 0
Reputation: 1254
I can only speak to Facebook and Twitter, as they are the only two Social Media API's I have utilized.
Both API's are RESTful services. For Twitter and Facebook, you will need to create applications on the perspective platforms in order to obtain an OAuth token for your applications that will be fetching the data via the RESTful services.
For FaceBook, you can utilize the Graph API explorer for development. This enables you to develope without creating an application on the FaceBook platform.
Both FaceBook and Twitter have community driven projects for accessing these web services in various languages. Since you are doing this for the Android, I assume you would like your program for fetching this data in Java.
RestFB is my recommendation for a Java FaceBook library
FacebookClient facebookClient = new DefaultFacebookClient(authToken);
User facebookUser = facebookClient.fetchObject("me", User.class);
Twitter4j is a great Java Twitter library
For FaceBook, core concepts is a great place to start. For more information on Twitter on see the overview documentation
Upvotes: 1