9 Replies - 1194 Views - Last Post: 20 June 2013 - 02:22 PM

#1 popa  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 15-February 13

Convert Facebook Post ID to Unix Time Stamp

Posted 19 June 2013 - 02:35 PM

I'm currently having an issue with a javascript that displays Facebook posts on an external website. However, I've run into a big issue. Currently it sorts posts and gives them a date depending on the posted date, but I backdated many posts to reflect their actual published date. We moved all of our old articles onto Facebook, so now we're using it as a method for updating our news section.

Here's an example:

Quote

Tuesday, May 28, 2013

Inside Science publishes WISDM article: Inside Science, a credentialed source for editorially independent research news and information in the fields of science, engineering, mathematics and related fields, publishes an article written by Dr. Gary Weiss regarding WISDM's mobile sensor mining research.


However, the post date on Facebook is actually January 4, 2013. I know the reason for this but I do not know if Facebook's API supports sorting graph posts in the format that I need.

Any suggestions are greatly appreciated, thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Convert Facebook Post ID to Unix Time Stamp

#2 popa  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 15-February 13

Re: Convert Facebook Post ID to Unix Time Stamp

Posted 19 June 2013 - 02:48 PM

I thought I might add the current javascript for calling the Facebook graph posts. Maybe it has something to do with

graphPOSTS = 'https://graph.facebook.com/'+options.id+'/posts/?access_token='+options.access_token+'&callback=?&date_format=l, F d, Y&limit='+options.limit;

but I'm not quite sure. In the html the implementation is ${created_time}, as you see in the javascript console.log(this.created_time); calls from the Facebook API. Is there a way to use the date rather than the created time, the same way it appears on Facebook's pages?

$(document).ready(function(){

	// Calling our plugin with a page id and an access token
	// that you will need to generate as explained in the tutorial:
	
	$('#wall').facebookWall({
		id:'wisdmlab',
		access_token:'myaccesstoken'
	});

});

// Creating our plugin. You can optionally
// place it in a separate file.

(function($){
	
	$.fn.facebookWall = function(options){
		
		options = options || {};
		
		if(!options.id){
			throw new Error('You need to provide an user/page id!');
		}
		
		if(!options.access_token){
			throw new Error('You need to provide an access token!');
		}
		
		// Default options of the plugin:
		
		options = $.extend({
			limit: 5000	// You can also pass a custom limit as a parameter.
		},options);

		// Putting together the Facebook Graph API URLs:

		var graphUSER = 'https://graph.facebook.com/'+options.id+'/?fields=name,picture&access_token='+options.access_token+'&callback=?',
			graphPOSTS = 'https://graph.facebook.com/'+options.id+'/posts/?access_token='+options.access_token+'&callback=?&date_format=l, F d, Y&limit='+options.limit;
		
		var wall = this;
		
		$.when($.getJSON(graphUSER),$.getJSON(graphPOSTS)).done(function(user,posts){
			
			// user[0] contains information about the user (name and picture);
			// posts[0].data is an array with wall posts;
			
			var fb = {
				user : user[0],
				posts : []
			};

			$.each(posts[0].data,function(){
				
				// We only show links and statuses from the posts feed:
				if((this.type != 'link' && this.type!='status') || !this.message){
					return true;
				}

				// Copying the user avatar to each post, so it is
				// easier to generate the templates:
				this.from.picture = fb.user.picture;
				
				// Converting the created_time (a UNIX timestamp) to
				// a relative time offset (e.g. 5 minutes ago):
				console.log(this.created_time);
								
				// Converting URL strings to actual hyperlinks:
				this.message = urlHyperlinks(this.message);

				fb.posts.push(this);
			});

			// Rendering the templates:
			$('#headingTpl').tmpl(fb.user).appendTo(wall);
			
			// Creating an unordered list for the posts:
			var ul = $('<ul>').appendTo(wall);
			
			// Generating the feed template and appending:
			$('#feedTpl').tmpl(fb.posts).appendTo(ul);
		});
		
		return this;

	};

	// Helper functions:
	// Remove or convert UTC 
	function urlHyperlinks(str){
		return str.replace(/\b((http|https):\/\/\S+)/g,'<a href="$1" target="_blank">$1</a>');
	}
	
})(jQuery);

Was This Post Helpful? 0
  • +
  • -

#3 popa  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 15-February 13

Re: Convert Facebook Post ID to Unix Time Stamp

Posted 19 June 2013 - 10:24 PM

Any thoughts?
Was This Post Helpful? 0
  • +
  • -

#4 popa  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 15-February 13

Re: Convert Facebook Post ID to Unix Time Stamp

Posted 20 June 2013 - 11:51 AM

I currently have a javascript that uses Facebook's Graph API to embed posts on the news section of my website. Everything works, apart from the backdated posts. The posts' id have a Unix time stamp associated to them, thus I have multiple entries with May 28, 2013 as the post date. However, I do understand that there might be a way to fix this through a series of do while loops and creating an array for the posts that need conversion.

Here's some examples of what's going wrong.

The following image outlines the current Facebook page's backdated post time. We had posts from 2009 that were posted on May 28, 2013 to reflect their "actual" publish date on our website before we started using Facebook's timeline.

Attached Image

The next image shows the javascript code's implementation on our website with the May 28, 2013 post date. All of the May 28, 2013 posts should reflect dates ranging from May 2009 to January 2013.

Attached Image

I've sorted all of the post ID's and linked them to a Unix time-stamp of what they're suppose to read.

Attached Image

And lastly, the main thing that I need help with is the pseudo code for converting the 27 erroneous posts.
Array {TS1, TS2, TS3, ...}
do {
for reach (FB ID as $var){
ID.timestamp = Array [i]; i++;
}
} while (i ≤ 26)



I'm pretty new to programming, I've only really wrote basic programs in C++, so javascript syntax and logic is a bit difficult for me, especially in this situation.
Was This Post Helpful? 0
  • +
  • -

#5 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9048
  • View blog
  • Posts: 33,970
  • Joined: 12-June 08

Re: Convert Facebook Post ID to Unix Time Stamp

Posted 20 June 2013 - 12:12 PM

Please do not create duplicate topics. Merging.
Was This Post Helpful? 0
  • +
  • -

#6 popa  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 15-February 13

Re: Convert Facebook Post ID to Unix Time Stamp

Posted 20 June 2013 - 12:23 PM

View Postmodi123_1, on 20 June 2013 - 12:12 PM, said:

Please do not create duplicate topics. Merging.


Thanks and sorry, I sort of forgot that I made this post. I've been working on fixing a few things today, it slipped my mind. :)
Was This Post Helpful? 0
  • +
  • -

#7 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 436
  • View blog
  • Posts: 1,840
  • Joined: 30-April 10

Re: Convert Facebook Post ID to Unix Time Stamp

Posted 20 June 2013 - 01:43 PM

This from the docs shows you the object returned. The object returned will have the data object returned and it will contain the created_time object that will contain something like this represented in JSON.
"data": [
    {
      "created_time": "2013-06-19T14:10:11+0000",
      "id": "1097441106_4974151907069"
    }


Once you have the JSON you can access these and sort my created_time.

Note that this also returns a updated_time you may want to check to see if this is more recent before sorting.

I hope this is what you were asking.
Was This Post Helpful? 1
  • +
  • -

#8 popa  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 15-February 13

Re: Convert Facebook Post ID to Unix Time Stamp

Posted 20 June 2013 - 01:52 PM

View Postlaytonsdad, on 20 June 2013 - 01:43 PM, said:

This from the docs shows you the object returned. The object returned will have the data object returned and it will contain the created_time object that will contain something like this represented in JSON.
"data": [
    {
      "created_time": "2013-06-19T14:10:11+0000",
      "id": "1097441106_4974151907069"
    }


Once you have the JSON you can access these and sort my created_time.

Note that this also returns a updated_time you may want to check to see if this is more recent before sorting.

I hope this is what you were asking.


I tried replacing created_time with updated_time and it produces the same results.
Was This Post Helpful? 0
  • +
  • -

#9 laytonsdad  Icon User is offline

  • Cheese and Sprinkles
  • member icon

Reputation: 436
  • View blog
  • Posts: 1,840
  • Joined: 30-April 10

Re: Convert Facebook Post ID to Unix Time Stamp

Posted 20 June 2013 - 02:09 PM

If the file is not edited it will be the same stamp as the created time.

This post has been edited by laytonsdad: 20 June 2013 - 02:10 PM

Was This Post Helpful? 0
  • +
  • -

#10 popa  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 53
  • Joined: 15-February 13

Re: Convert Facebook Post ID to Unix Time Stamp

Posted 20 June 2013 - 02:22 PM

Understood. However, I think both created_time and updated_time would remain a problem. They would have NEW times associated with them, but at the same time I'm looking to set a static date (Unix timestamp) associated to the 27 erroneous posts.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1