I'm working on a social media project where in I need to follow a few fanpages and listen to all whats happening on that particular page. I for a fact know that there are some data resellers like GNIP & Datasift who can provide me such data. I have tried both trials.
What I want to know is that, is there a way to do this via the Facebook public feed & graph APIS, I know with this I'll be restricted only to a open posts, but that's ok for now.
I have downloaded the Facebook C# SDK and I'm able to get details of the Fan Pages, Album comments for groups I have credentials of but is there a way to get real-time updates through the api?
For e.g I want insert all that happens on my pages into a DB for reporting. I want to keep a track of any posts (photos/videos/status/events) and people's comments on it.
I read this link explaining the realtime updates API.But I do not know how to go about it using facebook C# SDK.I have never setup a callback url ,I ain't familiar with it, but is this the solution where in using Facebook C# SDK I can get some callbacks that a new interaction occured?
Thanks in advance. I may sound very boggling but I'm sure I've done justice in explaining my point.
Here is some sample code that I have tried:
public void FBPing() {
var client = new FacebookClient();
//dynamic FBObj = client.Get("fanpagename", new { fields = "albums" });
dynamic FBObj = client.Get("fanpagename");
OutputBox.AppendText(" about " + FBObj.about + "\r\n\r\n");
OutputBox.AppendText(" username" + FBObj.username + "\r\n\r\n");
OutputBox.AppendText(" category " + FBObj.category + "\r\n\r\n");
OutputBox.AppendText(" likes " + FBObj.likes + "\r\n\r\n");
OutputBox.AppendText(" talking_about_count " + FBObj.talking_about_count + "\r\n\r\n");
OutputBox.AppendText(" were_here_count " + FBObj.were_here_count + "\r\n\r\n");
OutputBox.AppendText(" description " + FBObj.description + "\r\n\r\n");
OutputBox.AppendText(" company_overview " + FBObj.company_overview + "\r\n\r\n");
OutputBox.AppendText(" genre " + FBObj.genre + "\r\n\r\n");
OutputBox.AppendText(" is_published " + FBObj.is_published + "\r\n\r\n");
OutputBox.AppendText(" plot_outline " + FBObj.plot_outline + "\r\n\r\n");
OutputBox.AppendText(" release_date " + FBObj.release_date + "\r\n\r\n");
OutputBox.AppendText(" starring " + FBObj.starring + "\r\n\r\n");
OutputBox.AppendText(" username " + FBObj.username + "\r\n\r\n");
OutputBox.AppendText(" website " + FBObj.website + "\r\n\r\n");
OutputBox.AppendText(" written_by " + FBObj.written_by + "\r\n\r\n");
OutputBox.AppendText(" id " + FBObj.id + "\r\n\r\n");
OutputBox.AppendText(" name " + FBObj.name + "\r\n\r\n");
OutputBox.AppendText(" link " + FBObj.link + "\r\n\r\n");
OutputBox.AppendText(" Cover cover_id " + FBObj.cover.cover_id + "\r\n\r\n");
OutputBox.AppendText(" Cover source " + FBObj.cover.source + "\r\n\r\n");
}
EDIT 1
This post tells me that I need a combination of Facebook Public Feed API & Graph API to achieve what I want to but I'm still a newbee when it comes to setting up an HTTPS endpoint or creating a call back url. Do they both mean the same?
Also I have seen this github that explains ASP.NET Callback ashx. I think I'm almost there and have done a lot of research. I would just want someone to connect the dots for me, so I see the picture clearly. I will keep updating this questions as I find something.
EDIT 2
I have queried both the GRAPH API and FQL for data, what I now need is only to setup an HTTP endpoint to get real-time updates from the public feed api. I wonder if I could use Messaging Queues here like MSMQ or Rabbit MQ? Please share some concrete documentation links (as Facebook C# SDK lacks proper documentation), I will take it from there :)
Related
I have a Google Sheets script that emails a notification to a group of people when a form is submitted. It worked beautifully for months. Now it seems to have lost the access rights to send the emails. November 6, 2015 was the last time responses were submitted and successfully emailed. No more responses were submitted until yesterday (Sept 21, 2016) and it no longer has rights to send email. I verified that it is not listed in my Google account's security section under my "apps connected to your account".
I tried to re-authorize it by deleting all the triggers, saving and closing out the script. Then I reopened it and added the triggers back in. It didn't ask for a new authorization, but it still won't send emails.
Does anyone know why it might lose access rights? Does it get removed if it's not used periodically?
How do I force it to refresh/renew rights? Or do I just have to delete the script entirely and recreate a fresh copy?
This is just one of many similar scripts that I have so, I need to figure out how to make them work (and keep them working). Searching around I couldn't find anything except how to intentionally revoke access rights.
Here is my code so you can see what it's trying to do (I'm testing it with just my email address right now). I will admit I don't know a lot about programming scripts, so it may not be very pretty.
Thanks for any help!
function sendFormByEmail(e)
{
// Remember to replace this email address with your own email address
var email = "bjwarneke#gmail.com";
var quiz = "02.8-JLOT-D Drop-In";
var filename = "02-JLOT Exam Grading Instructions";
var s = SpreadsheetApp.getActiveSheet();
var headers = s.getRange(1,1,1,s.getLastColumn()).getValues()[0];
var message = "Time for someone to go grade a quiz from me!" + "<br>";
var replyto = e.namedValues[headers[1]].toString();
var subject = 'Quiz: ' + replyto;
//message += headers[1] + ': '+ e.namedValues[headers[1]].toString() + "\n";
//message += headers[0] + ': '+ e.namedValues[headers[0]].toString() + "\n";
message += headers[1] + ': '+ e.namedValues[headers[1]].toString() + "<br>";
message += headers[0] + ': '+ e.namedValues[headers[0]].toString() + "<br><br>";
message += quiz + "<br>";
message += ''+filename+'<br>';
// The variable e holds all the form values in an array.
// Loop through the array and append values to the body.
//for(var i in headers)
//message += headers[i] + ': '+ e.namedValues[headers[i]].toString() + "\n\n";
// Insert variables from the spreadsheet into the subject.
// In this case, I wanted the new hire's name and start date as part of the
// email subject. These are the 3rd and 16th columns in my form.
// This creates an email subject like "New Hire: Jane Doe - starts 4/23/2013"
//subject += e.namedValues[headers[2]].toString() + " - starts " + e.namedValues[headers[15]].toString();
// Send the email
MailApp.sendEmail(email, subject, message, {htmlBody:message, name:"Quiz", replyTo:replyto});
// Based off of a script originally posted by Amit Agarwal - www.labnol.org
// Credit to Henrique Abreu for fixing the sort order
}
Do you have a Gmail account associated with your Google Account? The MailApp service will only work if you have Gmail enabled for your account.
I am using IdentityServer3 and would like it so that User.Identity.GetUserName() and User.Identity.GetUserId() return the values stored in the Claims. Right now I see them in the claims as "sub" and "email". Is it possible to either:
Make IdentityServer3 return these as Claims? I'm guessing they would be nameidentifier and name.
Add the claims once the client app authenticates so that the User.Identity methods are usable.
Hopefully this made some sense and I appreciate any feedback.
I think I figured it out.
I added a new Scope to the Scopes class:
new Scope
{
Name = "public",
DisplayName = "Public scope",
Type = ScopeType.Identity,
IncludeAllClaimsForUser = true
}
Then I modified my login url in the SignIn action of the AccountController:
var url = Settings.AuthorizeEndpoint +
"?client_id=" + Settings.ClientId +
"&response_type=id_token" +
"&scope=openid email profile public" +
"&redirect_uri=" + Settings.RedirectUri +
"&response_mode=form_post" +
"&state=" + state +
"&nonce=" + nonce;
That seemed to do the trick.
I'm using graph API in order to use Facebook chat.
I'm using the http://restfb.com/ framework.
The issue is that with the following code I can read all conversations and messages.
public void initClient()
{
m_facebookClient = new DefaultFacebookClient(MY_ACCESS_TOKEN, MY_APP_SECRET);
}
public void readPage()
{
Page page = m_facebookClient.fetchObject("352179081632935", Page.class);
System.out.println("Page likes = " + page.getLikes());
Connection<Conversation> conversations = m_facebookClient.fetchConnection("me/conversations", Conversation.class);
for(List<Conversation> conversationPage : conversations) {
for(Conversation conversation : conversationPage) {
System.out.println(conversation);
System.out.println(conversation.getUnreadCount());
Message lastMessage = null;
for (Message message : conversation.getMessages())
{
System.out.println("Message text = " + message.getMessage());
System.out.println("Message unread = " + message.getUnread());
System.out.println("Message from = " + message.getFrom().getName());
System.out.println("Message to = " + message.getTo().get(0).getName());
System.out.println("Message unseen = " + message.getUnseen());
lastMessage = message;
}
}
}
I would like to know how to send reply messages or new messages using this framework or Graph API?
Thank you,
Moshe
First of all, there is no me/conversations endpoint for users. Conversations are only available for Pages so it would be /{page-id}/conversations: https://developers.facebook.com/docs/graph-api/reference/v2.2/page/conversations
The Facebook docs explain in detail how it works, including some example code. I suggest using one of the official SDKs instead (JS SDK, PHP SDK, ...).
The Chat API (which is what you would want to use) is deprecated: https://developers.facebook.com/docs/chat/
Meaning, it is not possible anymore to use the Facebook chat in your App.
I found the way yo solve it by replying based on the conversation id.
For example:
m_facebookClient.publish("t_mid.1420120490471:36257b35667389d257/messages", FacebookType.class, Parameter.with("message", "RestFB test"));
t_mid.1420120490471:36257b35667389d257 - is the conversation id
I'm struggling to get other user's mention timeline with twitter4j api. I could figure out that it's possible only to get other user's UserTimeline. It seems that there is no way to get other user's mention timeline
(I found that here - lookup "Interface TimelinesResources")
Is there way to get other user's mention timeline ???
You can get the MentionsTimeline using getMentionsTimeline() method of TimelineResources as a link you mentioned with some limitations of number of tweets returned.
Find below example of the example which will give you MentionsTimeline.
Twitter twitter = new TwitterFactory().getInstance();
try {
User user = twitter.verifyCredentials();
List<Status> statuses = twitter.getMentionsTimeline();
System.out.println("Showing #" + user.getScreenName() + "'s mentions.");
for (Status status : statuses) {
System.out.println("#" + status.getUser().getScreenName() + " - " + status.getText());
}
} catch (TwitterException te) {
te.printStackTrace();
System.out.println("Failed to get timeline: " + te.getMessage());
System.exit(-1);
}
You can use getUserTimeline() method of Twitter class.
References:
1. http://twitter4j.org/javadoc/twitter4j/Twitter.html
2. http://twitter4j.org/javadoc/twitter4j/Status.html
The Twitter API doesn't have an endpoint for viewing other users mentions (the statuses/mentions_timeline API returns only the mentions of the authenticated user).
You should use the search API, using as the query string the #screen_name of the user you want to get the mentions. Please note that the Twitter Search API may not return all mentions for a given user (it says that "the Search API is focused on relevance and not completeness").
So, using Twitter4j, you can get #NASA mentions using the following
Twitter twitter = new TwitterFactory().getInstance();
try {
Query query = new Query("#NASA");
QueryResult result;
do {
result = twitter.search(query);
List<Status> tweets = result.getTweets();
for (Status tweet : tweets) {
System.out.println("#" + tweet.getUser().getScreenName() + " - " + tweet.getText());
}
} while ((query = result.nextQuery()) != null);
System.exit(0);
} catch (TwitterException te) {
te.printStackTrace();
}
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
https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=screenname&count=2
Is there any library or any particular way by which i can get it?
Thanks in Advance.
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
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 += "" + comments[j].actor.displayName + "";
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 += " " + comments[j].actor.displayName + "";
renderMe += "</p>";
}
}
renderMe += "</div>";
}
}
console.log("I'm done");
document.getElementById(identifier).innerHTML = renderMe;
return renderMe;
}