public function testArrayProperties() { $backingData = array('id' => 42, 'friends' => array('data' => array(array('id' => 1, 'name' => 'David'), array('id' => 2, 'name' => 'Fosco')), 'paging' => array('next' => 'nexturl'))); $obj = new GraphObject($backingData); $friends = $obj->getPropertyAsArray('friends'); $this->assertEquals(2, count($friends)); $this->assertTrue($friends[0] instanceof GraphObject); $this->assertTrue($friends[1] instanceof GraphObject); $this->assertEquals('David', $friends[0]->getProperty('name')); $this->assertEquals('Fosco', $friends[1]->getProperty('name')); $backingData = array('id' => 42, 'friends' => array(array('id' => 1, 'name' => 'Ilya'), array('id' => 2, 'name' => 'Kevin'))); $obj = new GraphObject($backingData); $friends = $obj->getPropertyAsArray('friends'); $this->assertEquals(2, count($friends)); $this->assertTrue($friends[0] instanceof GraphObject); $this->assertTrue($friends[1] instanceof GraphObject); $this->assertEquals('Ilya', $friends[0]->getProperty('name')); $this->assertEquals('Kevin', $friends[1]->getProperty('name')); }
// FacebookJavaScriptLoginHelper // or create a FacebookSession with a valid access token: $session = new FacebookSession($app_token); $coins_for_product = ['{$serverUrl}/payments/100coins.html' => 100, '{$serverUrl}/payments/500coins.html' => 500, '{$serverUrl}/payments/1000coins.html' => 1000]; // Get the GraphUser object for the current user: $method = $_SERVER['REQUEST_METHOD']; //stdout('RTU'); if ($method == 'GET' && $_GET['hub_verify_token'] === $verify_token) { echo $_GET['hub_challenge']; } else { $data = file_get_contents("php://input"); $json = json_decode($data, true); if ($json["object"] && $json["object"] == "payments") { $payment_id = $json["entry"][0]["id"]; try { $result = (new FacebookRequest($session, 'GET', '/' . $payment_id . '?fields=user,actions,items,gift_requests'))->execute()->getGraphObject(GraphObject::className()); error_log('payment id: ' . $result->getProperty('id')); $actions = $result->getPropertyAsArray('actions'); if ($actions[0]->getProperty('status') == 'completed') { $gift_requests = $result->getProperty('gift_requests'); $user = $result->getProperty('user'); $items = $result->getPropertyAsArray('items'); $product = $items[0]->getProperty('product'); $coins = $coins_for_product[$product]; error_log('product ' . $product); $recipient = ''; if ($gift_requests) { $data = $gift_requests->getPropertyAsArray('data'); $recipient = $data[0]->getProperty('to')->getProperty('id'); error_log('gift to ' . $recipient); } else {
/** * Runs an FQL query and return its content * * @param String $query A valid FQL query * @param String $castAs Cast the result as a specialized GraphObject (GraphAlbum, GraphLocation, GraphUser) * @return GraphObject */ public function executeFQLQuery($query, $castAs = NULL) { if ($castAs === NULL) { $castAs = GraphObject::className(); } return (new FacebookRequest($this->facebookSession, 'GET', '/fql', ['access_token' => $this->facebookSession->getToken(), 'q' => $query]))->execute()->getGraphObject($castAs); }
$title = splitMessage(wordwrap($message, $titleLength), "title"); $content = str_replace($title, "...", $message); $title .= "..."; } if ($returnItem == "title") { return $title; } else { return $content; } } $feed = new Feed(); $channel = new Channel(); $channel->title($channelTitle)->description($channelDesc)->url($channelUrl)->language($channelLanguage)->copyright($channelCopyRight)->pubDate(date("U"))->lastBuildDate(date("U"))->appendTo($feed); // Make a new request and execute it. try { $posts = (new FacebookRequest($session, 'GET', '/' . $page_id . '/posts'))->execute()->getGraphObject(GraphObject::className())->getPropertyAsArray('data'); //print_r($posts); foreach ($posts as $dings) { $type = $dings->getProperty('type'); $message = $dings->getProperty('message'); if (empty($message)) { continue; } $id = $dings->getProperty('id'); $title = splitMessage($message, "title"); $content = splitMessage($message, "content"); $createdAt = date("U", strtotime($dings->getProperty('created_time'))); $updatedAt = strtotime($dings->getProperty('updated_time')); $link = $dings->getProperty('link'); $picture = $dings->getProperty('picture'); //print("$title: <br/>" . $content . "<br/><br/>");