コード例 #1
0
 function it_fetches_data_from_next_page(Facebook $fb, FacebookResponse $firstPageResponse, FacebookResponse $secondPageResponse)
 {
     $firstPageResponse->getDecodedBody()->willReturn(['data' => [['name' => 'John Doe'], ['name' => 'Peter Falk'], ['name' => 'James Bond']], 'paging' => ['next' => 'nextPageUrl', 'cursors' => ['after' => 'nextPageId']]]);
     $fb->get('/eventId/attending', self::ACCESS_TOKEN)->willReturn($firstPageResponse);
     $secondPageResponse->getDecodedBody()->willReturn(['data' => [['name' => 'Bruce Lee'], ['name' => 'Sean Connery']]]);
     $fb->get('/eventId/attending?after=nextPageId', self::ACCESS_TOKEN)->willReturn($secondPageResponse);
     $this->get('eventId', self::ACCESS_TOKEN)->shouldReturn(['Bond James', 'Connery Sean', 'Doe John', 'Falk Peter', 'Lee Bruce']);
 }
コード例 #2
0
 public function testErrorStatusCanBeCheckedWhenAnErrorResponseIsReturned()
 {
     $graphResponse = '{"error":{"message":"Foo error.","type":"OAuthException","code":190,"error_subcode":463}}';
     $response = new FacebookResponse($this->request, $graphResponse, 401);
     $exception = $response->getThrownException();
     $this->assertTrue($response->isError(), 'Expected Response to return an error.');
     $this->assertInstanceOf('Facebook\\Exceptions\\FacebookResponseException', $exception);
 }
コード例 #3
0
ファイル: GraphPageTest.php プロジェクト: barabash97/coolpost
 public function testLocationPropertyWillGetCastAsGraphLocationObject()
 {
     $dataFromGraph = ['id' => '123', 'name' => 'Foo Page', 'location' => ['city' => 'Washington', 'country' => 'United States', 'latitude' => 38.881634205431, 'longitude' => -77.029121075722, 'state' => 'DC']];
     $this->responseMock->shouldReceive('getDecodedBody')->once()->andReturn($dataFromGraph);
     $factory = new GraphNodeFactory($this->responseMock);
     $graphNode = $factory->makeGraphPage();
     $location = $graphNode->getLocation();
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphLocation', $location);
 }
コード例 #4
0
 public function testParentGroupGetsCastAsGraphGroup()
 {
     $dataFromGraph = ['parent_group' => ['id' => '1337']];
     $this->responseMock->shouldReceive('getDecodedBody')->once()->andReturn($dataFromGraph);
     $factory = new GraphNodeFactory($this->responseMock);
     $graphObject = $factory->makeGraphEvent();
     $parentGroup = $graphObject->getParentGroup();
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphGroup', $parentGroup);
 }
コード例 #5
0
 /**
  * @param array $objects
  * @param FacebookResponse $response
  */
 public function __construct(array $objects, FacebookResponse $response)
 {
     $this->objects = $objects;
     $this->response = $response;
     /* @var $resp \StdClass */
     $resp = $response->getResponse();
     $this->before = isset($resp->paging->cursors->before) ? $resp->paging->cursors->before : null;
     $this->after = isset($resp->paging->cursors->after) ? $resp->paging->cursors->after : null;
 }
コード例 #6
0
ファイル: GraphAlbumTest.php プロジェクト: adityapooniya/olx
 public function testPlacePropertyWillGetCastAsGraphPageObject()
 {
     $dataFromGraph = ['id' => '123', 'name' => 'Foo Album', 'place' => ['id' => '1', 'name' => 'For Bar Place']];
     $this->responseMock->shouldReceive('getDecodedBody')->once()->andReturn($dataFromGraph);
     $factory = new GraphNodeFactory($this->responseMock);
     $graphNode = $factory->makeGraphAlbum();
     $place = $graphNode->getPlace();
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphPage', $place);
 }
コード例 #7
0
 public function testVenueGetsCastAsGraphLocation()
 {
     $dataFromGraph = ['venue' => ['id' => '1337']];
     $this->responseMock->shouldReceive('getDecodedBody')->once()->andReturn($dataFromGraph);
     $factory = new GraphNodeFactory($this->responseMock);
     $graphNode = $factory->makeGraphGroup();
     $venue = $graphNode->getVenue();
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphLocation', $venue);
 }
コード例 #8
0
 /**
  * A factory for creating the appropriate exception based on the response from Graph.
  *
  * @param FacebookResponse $response The response that threw the exception.
  *
  * @return FacebookResponseException
  */
 public static function create(FacebookResponse $response)
 {
     $data = $response->getDecodedBody();
     if (!isset($data['error']['code']) && isset($data['code'])) {
         $data = ['error' => $data];
     }
     $code = isset($data['error']['code']) ? $data['error']['code'] : null;
     $message = isset($data['error']['message']) ? $data['error']['message'] : 'Unknown error from Graph.';
     $previousException = null;
     if (isset($data['error']['error_subcode'])) {
         switch ($data['error']['error_subcode']) {
             // Other authentication issues
             case 458:
             case 459:
             case 460:
             case 463:
             case 464:
             case 467:
                 return new static($response, new FacebookAuthenticationException($message, $code));
         }
     }
     switch ($code) {
         // Login status or token expired, revoked, or invalid
         case 100:
         case 102:
         case 190:
             return new static($response, new FacebookAuthenticationException($message, $code));
             // Server issue, possible downtime
         // Server issue, possible downtime
         case 1:
         case 2:
             return new static($response, new FacebookServerException($message, $code));
             // API Throttling
         // API Throttling
         case 4:
         case 17:
         case 341:
             return new static($response, new FacebookThrottleException($message, $code));
             // Duplicate Post
         // Duplicate Post
         case 506:
             return new static($response, new FacebookClientException($message, $code));
     }
     // Missing Permissions
     if ($code == 10 || $code >= 200 && $code <= 299) {
         return new static($response, new FacebookAuthorizationException($message, $code));
     }
     // OAuth authentication error
     if (isset($data['error']['type']) && $data['error']['type'] === 'OAuthException') {
         return new static($response, new FacebookAuthenticationException($message, $code));
     }
     // All others
     return new static($response, new FacebookOtherException($message, $code));
 }
コード例 #9
0
 public function testDatesGetCastToDateTime()
 {
     $dataFromGraph = ['expires_at' => 123, 'issued_at' => 1337];
     $this->responseMock->shouldReceive('getDecodedBody')->once()->andReturn($dataFromGraph);
     $factory = new GraphNodeFactory($this->responseMock);
     $graphNode = $factory->makeGraphSessionInfo();
     $expires = $graphNode->getExpiresAt();
     $issuedAt = $graphNode->getIssuedAt();
     $this->assertInstanceOf('DateTime', $expires);
     $this->assertInstanceOf('DateTime', $issuedAt);
 }
コード例 #10
0
ファイル: GraphObjectTest.php プロジェクト: chenbingchn/demos
 public function testAsList()
 {
     $backingData = array('data' => array(array('id' => 1, 'name' => 'David'), array('id' => 2, 'name' => 'Fosco')));
     $enc = json_encode($backingData);
     $response = new FacebookResponse(null, json_decode($enc), $enc);
     $list = $response->getGraphObjectList(GraphUser::className());
     $this->assertEquals(2, count($list));
     $this->assertTrue($list[0] instanceof GraphObject);
     $this->assertTrue($list[1] instanceof GraphObject);
     $this->assertEquals('David', $list[0]->getName());
     $this->assertEquals('Fosco', $list[1]->getName());
 }
コード例 #11
0
ファイル: GraphUserTest.php プロジェクト: barabash97/coolpost
 public function testPicturePropertiesWillGetCastAsGraphPictureObjects()
 {
     $dataFromGraph = ['id' => '123', 'name' => 'Foo User', 'picture' => ['is_silhouette' => true, 'url' => 'http://foo.bar', 'width' => 200, 'height' => 200]];
     $this->responseMock->shouldReceive('getDecodedBody')->once()->andReturn($dataFromGraph);
     $factory = new GraphNodeFactory($this->responseMock);
     $graphNode = $factory->makeGraphUser();
     $Picture = $graphNode->getPicture();
     $this->assertInstanceOf('\\Facebook\\GraphNodes\\GraphPicture', $Picture);
     $this->assertTrue($Picture->isSilhouette());
     $this->assertEquals(200, $Picture->getWidth());
     $this->assertEquals(200, $Picture->getHeight());
     $this->assertEquals('http://foo.bar', $Picture->getUrl());
 }
コード例 #12
0
 /**
  * AdAccountGroup connections
  *
  * @param FacebookResponse $response
  * @param $prototype_class
  * @return Cursor
  */
 protected function getCursorByConnection(FacebookResponse $response, $prototype_class)
 {
     $result = array();
     $response_data = (array) $response->getResponse();
     if (!empty($response_data)) {
         foreach (array_shift($response_data) as $data) {
             /** @var AbstractObject $object */
             $object = new $prototype_class(null, null, $this->getApi());
             $object->setData((array) $data);
             $result[] = $object;
         }
     }
     return new Cursor($result, $response);
 }
コード例 #13
0
 /**
  * Based on previous wall request it will execute the pre previous wall request
  * @return array
  */
 public function previous()
 {
     $result = [];
     try {
         $request = $this->facebookResponse->getRequestForPreviousPage();
         $response = $request->execute();
         $this->facebookResponse = $response;
         $response = $response->getResponse();
         $result = $this->transformFacebookResponse($response->data);
     } catch (FacebookRequestException $ex) {
         echo $ex->getMessage();
     } catch (\Exception $ex) {
         echo $ex->getMessage();
     }
     return $result;
 }
コード例 #14
0
 /**
  * Creates a new Response entity.
  *
  * @param FacebookBatchRequest $batchRequest
  * @param FacebookResponse     $response
  */
 public function __construct(FacebookBatchRequest $batchRequest, FacebookResponse $response)
 {
     $this->batchRequest = $batchRequest;
     $request = $response->getRequest();
     $body = $response->getBody();
     $httpStatusCode = $response->getHttpStatusCode();
     $headers = $response->getHeaders();
     parent::__construct($request, $body, $httpStatusCode, $headers);
     $responses = $response->getDecodedBody();
     $this->setResponses($responses);
 }
コード例 #15
0
 protected function makeFactoryWithData($data)
 {
     $this->responseMock->shouldReceive('getDecodedBody')->once()->andReturn($data);
     return new GraphObjectFactory($this->responseMock);
 }
コード例 #16
0
 /**
  * Init this Graph object.
  *
  * @param FacebookResponse $response The response entity from Graph.
  */
 public function __construct(FacebookResponse $response)
 {
     $this->response = $response;
     $this->decodedBody = $response->getDecodedBody();
 }
コード例 #17
0
 /**
  * Makes the request to Graph and returns the result.
  *
  * @param FacebookRequest $request
  *
  * @return FacebookResponse
  *
  * @throws FacebookSDKException
  */
 public function sendRequest(FacebookRequest $request)
 {
     if (get_class($request) === 'FacebookRequest') {
         $request->validateAccessToken();
     }
     list($url, $method, $headers, $body) = $this->prepareRequestMessage($request);
     // Since file uploads can take a while, we need to give more time for uploads
     $timeOut = static::DEFAULT_REQUEST_TIMEOUT;
     if ($request->containsFileUploads()) {
         $timeOut = static::DEFAULT_FILE_UPLOAD_REQUEST_TIMEOUT;
     } elseif ($request->containsVideoUploads()) {
         $timeOut = static::DEFAULT_VIDEO_UPLOAD_REQUEST_TIMEOUT;
     }
     // Should throw `FacebookSDKException` exception on HTTP client error.
     // Don't catch to allow it to bubble up.
     $rawResponse = $this->httpClientHandler->send($url, $method, $body, $headers, $timeOut);
     static::$requestCount++;
     $returnResponse = new FacebookResponse($request, $rawResponse->getBody(), $rawResponse->getHttpResponseCode(), $rawResponse->getHeaders());
     if ($returnResponse->isError()) {
         throw $returnResponse->getThrownException();
     }
     return $returnResponse;
 }