Forum Discussion

Nav's avatar
Nav
Ace
7 years ago

Rest Apiv2 to retrieve messages with authentication

Hi,

I am working on ApiV2 rest call to retrieve all messages. I used the below

 

 

$aurl = "https://api.lithium.com/community/2.0/xxxxxxx/search?q=SELECT+*+FROM+messages&api.pretty_print=true";
print_r($aresponse = drupal_http_request($aurl, array('headers' => array('client_id' => 'xxxxxx','Content-Type' => 'application/json', 'client_secret' => 'xxx'),
)));exit;

I got the below error 

{"status":"Unauthorized","message":"Invalid Access Token. Please refresh the token","statusCode":401} [protocol] => HTTP/1.1 [status_message] => Internal Server Error 

Please suggest.

 

  • Hi

    This is working fine when I follow the below 

    https://community.xxxxxxxxxx.co.uk/auth/oauth2/authorize?client_id=xxxxxxxxxxx&response_type=code&redirect_uri=http://community.xxxx.co.uk/

    Thanks

    • Nav's avatar
      Nav
      Ace

      Hi TariqHussain,

      Thanks for your reply. I used below 

      $aurl = "https://community.xxxxx.com/auth/oauth2/authorize?client_id=xxxxxxx&response_type=code&redirect_uri=http://redirect.xxx.com/getaccessToken";
      print_r($aresponse = drupal_http_request($aurl, array('headers' => array('client_id' => 'xxxx','Content-Type' => 'application/json' ))));
      exit;

      I received 

      stdClass Object ( [code] => -110 [error] => Connection timed out )

      Did I miss anything and what is the redirect Url? 

      Thanks.

      • Nav-

         

        You can get the Redirect URL from the app which you have created on community. 

        Community Admin > System > API Apps

         

         

         

         

    • Nav's avatar
      Nav
      Ace

      Hi TariqHussain

       

      I used the below request 

      https://community.xxxxx.com/auth/oauth2/authorize?client_id=Cxxxxxxx&response_type=code&redirect_uri=http://redirect.example_community.com/getaccessToken

      I am receiving  

      ..
      .
      .
      [protocol] => HTTP/1.1 [status_message] => OK [headers] => Array ( [date] => Mon, 05 Mar 2018 13:47:25 GMT [server] => Apache [set-cookie] => LiSESSIONID=xxxxx; Path=/; Secure; HttpOnly,LithiumUserInfo=""; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/,LithiumUserSecure=""; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/,LithiumVisitor=~2EdU7eARNliMf0JTU~ismlM5b4659flt5cOo6S0aig7ASj3dydeq8_Y1F2NZxzQZLt2cFkeOAG8WWOqPZqWUWLldiW5U6rl_SHvwPhPw..; Expires=Thu, 02-Mar-2028 13:47:25 GMT; Path=/; HttpOnly [pragma] => no-cache [expires] => Thu, 01 Jan 1970 00:00:00 GMT [cache-control] => no-cache, no-store, must-revalidate, private [x-frame-options] => DENY [vary] => Accept-Encoding [connection] => close [content-type] => text/html;charset=UTF-8 ) [code] => 200 [redirect_code] => 302 [redirect_url] => https://community.xxxx.co.uk/t5/user/userloginpage?redirectreason=notregistered&dest_url=https%3A%2F%2Fcommunity.xxxx.co.uk%2Ft5%2Foauth%2F2userauthorizationpage

      In data i recived Lithium login page with the error message 'Sorry, unable to complete the action you requested.' ?

      Please suggest.

      Thanks.