Exemplo n.º 1
0
 function it_should_return_access_token(OAuthProvider $provider, StubSession $session, AccessToken $accessToken)
 {
     $authorizationCode = 'foobar-authorization-code';
     $provider->getAccessToken('authorization_code', ['code' => $authorizationCode])->shouldBeCalled()->willReturn($accessToken);
     $accessToken->getToken()->shouldBeCalled()->willReturn($token = 'foo-token');
     $session->put('instamob.oauth_access_token', $token)->shouldBeCalled();
     $this->authorize($authorizationCode);
     $session->get('instamob.oauth_access_token')->shouldBeCalled()->willReturn('foo-token');
     $this->accessToken()->shouldBeEqualTo('foo-token');
 }
 /**
  * Fetch Instagram data for authorized user
  *
  * @return mixed
  */
 public function getFeedUncached()
 {
     $provider = new Instagram(['clientId' => $this->ClientID, 'clientSecret' => $this->ClientSecret, 'redirectUri' => $this->getRedirectUri() . '?provider_id=' . $this->ID]);
     $request = $provider->getRequest('GET', 'https://api.instagram.com/v1/users/self/media/recent/?access_token=' . $this->AccessToken);
     try {
         $result = $provider->getResponse($request);
     } catch (Exception $e) {
         $errorHelpMessage = '';
         if ($e->getCode() == 400) {
             // "Missing client_id or access_token URL parameter." or "The access_token provided is invalid."
             $cmsLink = Director::absoluteBaseURL() . 'admin/social-feed/SocialFeedProviderInstagram/EditForm/field/SocialFeedProviderInstagram/item/' . $this->ID . '/edit';
             $errorHelpMessage = ' -- Go here ' . $cmsLink . ' and click "Authorize App to get Access Token" to restore Instagram feed.';
         }
         // Throw warning as we don't want the whole site to go down if Instagram starts failing.
         user_error($e->getMessage() . $errorHelpMessage, E_USER_WARNING);
         $result['data'] = array();
     }
     return $result['data'];
 }
Exemplo n.º 3
0
 /**
  * Retrieve OAuth2 access token for authenticated user
  *
  * @param  srting $authorizationCode
  *
  * @return \Instamob\Contracts\AuthInterface
  */
 public function authorize($authorizationCode)
 {
     $this->accessToken = $this->provider->getAccessToken('authorization_code', ['code' => $authorizationCode]);
     $this->session->put('instamob.oauth_access_token', $this->accessToken->getToken());
     return $this;
 }