Listing latest actions using opengraph api - javascript

We're developing an application, based on the open graph API. In our application the user will read news and after 15 seconds of reading an action will appear on the reader's wall.
I need a way, using the open graph API, to get the last actions, posted on the reader's wall. I need it in order to give the users the ability to delete those actions. I found in the facebook documentation how to delete an action, using the action's id.
However I could not find how to get the latest actions ids that came from my App.
Is there a way to get them or I must store them on my server after a successful action post?
P.S I am using the javascript API.

Just issue a GET request to the API asking for /userid/app_namespace:action_name, and it will return the actions of that type published for that user.

Related

AJAX - How can I build a notification system, that is constantly getting updated, without slowing down my website too much?

I am a beginner to web development, and I am trying to do a notification system with AJAX and jQuery.
In my web application, I have a comment system where you can mention another user. After a comment mentioning a certain user has been written, a new entry on my notifications table will be added, containing the comment, the id of the user who commented and the id of the user(s) who will receive the comment. After the notification is stored in the database, I want the person that was mentioned to receive the notification.
To that effect, I decided to use AJAX. Using the setTimeout() method, I am sending an AJAX request to the database every 2 seconds, and with that, I can display the notifications visually to the user that is meant to receive them.
My only concern is that this will slow down the site once I connect it with a server.
So, I was looking for a way that would allow me to implement a notifications system without slowing the site too much, since the one that I am using currently doesn't seem very efficient.
I would appreciate any help.

Automatically access my Google Analytics and display chart publicly on my website

I'm having some difficulties in figuring out the best way to do this:
Using Google Analytics API, or similar Google API, I would like to track a user's activity from the moment they access the page until they reach an end page, which is gonna show them back some charts with THEIR activity on my website. (Nothing too detailed, just how long they've been on each page, how many session etc.)
So far, I've managed follow the Embed API example to access THE USER's Google Analytics account and draw a chart by asking for permission, however when it comes to showing data from MY account I just can't seem to figure it out.
I want my website to automatically use my account (or service account) and draw some charts from my google analytics data and show it to every user.
What would be the best way to approach this? I've read something about access tokens but I don't know if that's the solution. Moreover, my hosting is a shared host and I don't think it allows installing Python Modules like in this example.
Cheers for the help!
If you want to show the user your data, you will have to perform the authentication on the server side. There is no way around this. It is after all, your account's data that they are accessing.
If you are unable to install Google's client library, you need to:
Get an access token using cURL (see how here)
Use that access token to perform server side authentication for the user (see how here)
The user should now be able to access your site without logging in, and see YOUR data.

Building my own database of Facebook posts by calling Graph API via Server?

I want to build my own database of Facebook posts by periodically calling the Facebook Graph API and saving the results. User would then communicate with my own database instead of directly with Facebook.
I know that the API calls require an Access token that is generated from your Facebook login. From what I understand, this means the user logging in on the clientside would be using their own access token to make the calls. However, I want to make the calls from the server, which means using my own access token.
To illustrate the process flow:
*SERVER*
myFBAccessToken ---(API call every 15 mins)---> Facebook ---(returns)---> Fb posts ---(save to)---> myDatabase
*CLIENT*
viewFbPosts ---(db call)---> myDatabase
My questions are:
----------------------
1. Is it possible to use a single access token to regularly call the API from server? (Every 15 mins)
2. Will doing so violate any usage limitations on how frequently you can call the API?
3. Does Facebook allow for storing of their content on external databases?
Alternatively, if this is not recommended, does anyone know of a way to get more than the latest 25 posts from the facebook /feed?
I am using MEAN stack (mongodb, expressjs, angularjs, nodejs) with asynchronous functions.
Yes, you can use the same token for the same user multiple times. However, once it expires, you will have to re-login your user again to get a new access token.
There is not an official limitation of number of queries that you are sending to graph API. However, being involved in this sphere for a long time, I found out that 1 query per 1 second is workable for a single user. If you try to exceed it, you will most probably get JSON with error.
You do not have to notify facebook that you are going to store its data in external database. You simply get permitted information using graph API and, afterwards, it is totally up to you what you are going to do with the data. Facebook is responsible for flow of the data from their servers and making sure that you are the person who has a right to get that information on a legal basis.

How do I find out if my Open Graph app has already been added to the Timeline programmatically?

Assume, that besides using the "Add to Timeline" Social Plugin I want to show a specific message to the user only if she did not yet add my app to her Timeline.
Is there any method in the JavaScript SDK that lets me check for that?
According to what i have read, add to Timeline plugin is available through the Javascript SDK via the XFBML tag.
https://developers.facebook.com/docs/reference/plugins/add-to-timeline/
There doesn't seem to be a call that we can subscribe to at the moment.
There is no coverage of how to read from the timeline via the various APIs [yet].
However you can capture and save the ID of any post made, store that in your local database and use it to reference off of either for determining what to share or to let them delete previous posts.
This is a good practice even if the ID doesn't help you as both Facebook and the user want you to be transparent in your posting and the management of said posts.

Using jquery need to display facebook user name in html page

Using jquery (javascript) need to display facebook user name in html page using facebook user id. I am not using facebook api. Any one have any idea.
Without using the facebook API (Graph API or older facebook REST API) either javascript or PHP there's no way you can achive this.
Facebook needs to authenticate your application before you ask for data.
You can use fb:name from FBML (Facebook Markup Language) to achive it easily. But as recoomended, you should not use FBML for new applications since the recommended way is the new Graph API. FBML is in the process of being deprecated.
Using the new Graph API you can get the JSON object for the user by fetching https://graph.facebook.com/{userID}
You need to use the Facebook API as Facebook needs to authenticate your application's requests for user data. (http://developers.facebook.com/docs/api#authorization)
I recommend using the Graph API (http://developers.facebook.com/docs/api), but it takes a bit of work getting started.
I use the PHP SDK (http://github.com/facebook/php-sdk/), though others also exist and you can find them in the Facebook Documentation.
However, to answer your question better, If you have your authorization token you can make calls for example:
https://graph.facebook.com/me?access_token=<Your Access token>
would return a JSON object containing your basic information, including your name, birthday, and basically everything that appears on your profile.
Before doing anything you MUST register your own application at www.facebook.com/developers/
(Edit: I was not aware FBML was being phased out)
I know it's an old thread, but so that people doesn't get mislead...
There is NO need for Facebook to authenticate your application before you ask for data like user name because user name is public info and does not require permission. Just call https://graph.facebook.com/{userID} and you will get a JSON object. You can achieve this easily using jquery:
$.get("https://graph.facebook.com/{userID}", function (data) {
alert(data.name);
}, 'jsonp');

Categories

Resources