From b3d813b7aa558dce3769c75d12a911a432082d82 Mon Sep 17 00:00:00 2001 From: Ben Liyanage Date: Wed, 8 Oct 2014 14:50:38 -0400 Subject: [PATCH] got some initial fields set --- fbsync/object/Facebook_Graph21.php | 34 +++++++++++++++++++---------- fbsync/tests/fbsync_test.php | 22 +++++++++++++++---- fbsync/tests/graph2.1-no-filter.txt | 32 --------------------------- 3 files changed, 41 insertions(+), 47 deletions(-) diff --git a/fbsync/object/Facebook_Graph21.php b/fbsync/object/Facebook_Graph21.php index 0c459f4f..2de68e8c 100644 --- a/fbsync/object/Facebook_Graph21.php +++ b/fbsync/object/Facebook_Graph21.php @@ -1,41 +1,53 @@ uid = $uid; + $this->access_token = get_pconfig($uid,'facebook','access_token'); } - function CreatePost($a, $uid, $self, $contacts, $applications, $post, $create_user) + function CreatePost($a, $self, $contacts, $applications, $post, $create_user) { //Sanitize Inputs //Check if post exists //This is legacy--shouldn't we check if the various parts of the post was updated? $r = q("SELECT * FROM `item` WHERE `uid` = %d AND `uri` = '%s' LIMIT 1", - intval($uid), - dbesc('fb::'.$post->post_id) + intval($this->uid), + dbesc('fb::'.$post->id) ); if(count($r)) return; $postarray = array(); $postarray['gravity'] = 0; - $postarray['uid'] = $uid; + $postarray['uid'] = $this->uid; $postarray['wall'] = 0; $postarray['verb'] = ACTIVITY_POST; $postarray['object-type'] = ACTIVITY_OBJ_NOTE; // default value - is maybe changed later when media is attached $postarray['network'] = dbesc(NETWORK_FACEBOOK); - $postarray['uri'] = "fb::".$post->post_id; + $postarray['uri'] = "fb::". $post->id; $postarray['thr-parent'] = $postarray['uri']; $postarray['parent-uri'] = $postarray['uri']; - $postarray['plink'] = $post->permalink; + + //No permalink in new api. Can use one of the action links, they seem to be all the same. + //Another option is spliting the id AAA_BBB where AAA is the id of the person, and BBB is the ID of the post. final url would be facebook.com/AAA/post/BBB + $ids = split("_", $post->id); + $postarray['plink'] = 'https://www.facebook.com/' . $ids[0] . '/posts/' . $ids[1]; + + return $postarray; + } + } + ?> \ No newline at end of file diff --git a/fbsync/tests/fbsync_test.php b/fbsync/tests/fbsync_test.php index 3ae2596e..e81c6372 100644 --- a/fbsync/tests/fbsync_test.php +++ b/fbsync/tests/fbsync_test.php @@ -15,6 +15,7 @@ $db = new dba($db_host, $db_user, $db_pass, $db_data, $install); //var_dump($data); //Test Data Processing +$uid = 1; // Test Base Class require_once("./addon/fbsync/object/Facebook.php"); @@ -22,10 +23,23 @@ $myFBSync = new Facebook(); // Test graph 2.1 class require_once("./addon/fbsync/object/Facebook_Graph21.php"); -$myFBSync = new Facebook_Graph21(); -$uid = 1; -$post = json_decode(readfile("./addon/fbsync/tests/graph2.1.txt")); -$myFBSync->CreatePost($a,$uid,0,0,0,$post,0); +$myFBSync = new Facebook_Graph21($uid); + +//verify class loaded correctly +if ($myFBSync->uid != 1) die("class did not load"); +if ($myFBSync->access_token == '') die("failed to load access_token"); + + +$posts = json_decode(file_get_contents("./addon/fbsync/tests/graph2.1.txt")); + +$post = $myFBSync->CreatePost($a,0,0,0,$posts->data[0],0); + +//verify data +if ($post['uri'] != "fb::109524391244_10152483187826245") die("uri does not match"); +if ($post['plink'] != "https://www.facebook.com/109524391244/posts/10152483187826245") die("plink does not match"); + +//var_dump($posts->data[0]); +//test creating the same post again /* diff --git a/fbsync/tests/graph2.1-no-filter.txt b/fbsync/tests/graph2.1-no-filter.txt index 96a463d9..d28c49c7 100644 --- a/fbsync/tests/graph2.1-no-filter.txt +++ b/fbsync/tests/graph2.1-no-filter.txt @@ -49,38 +49,6 @@ }, "created_time": "2014-10-08T16:01:20+0000", "updated_time": "2014-10-08T16:01:20+0000" - }, - { - "id": "146218052067513_801079643248014", - "from": { - "category": "Local business", - "category_list": [ - { - "id": "2500", - "name": "Local Business" - } - ], - "name": "The Loading Dock, Inc.", - "id": "146218052067513" - }, - "message": "Blow In Insulation\n\n$2/ bag\n\nEach bag covers about 10 sf (at 6\" thickness)\n\nInsulation is used but very, very clean.\n\nRoughly 860 sf is available.", - "actions": [ - { - "name": "Comment", - "link": "https://www.facebook.com/146218052067513/posts/801079643248014" - }, - { - "name": "Like", - "link": "https://www.facebook.com/146218052067513/posts/801079643248014" - } - ], - "privacy": { - "value": "" - }, - "type": "status", - "status_type": "mobile_status_update", - "created_time": "2014-10-08T15:56:47+0000", - "updated_time": "2014-10-08T15:56:47+0000" } ], "paging": {