PHP Classes

Insteon API support

Recommend this page to a friend!

      PHP OAuth Library  >  PHP OAuth Library package blog  >  How to Implement a PH...  >  All threads  >  Insteon API support  >  (Un) Subscribe thread alerts  
Subject:Insteon API support
Summary:Insteon API support
Messages:4
Author:Fred Wittekind
Date:2020-02-02 18:03:05
 

  1. Insteon API support   Reply   Report abuse  
Picture of Fred Wittekind Fred Wittekind - 2020-02-02 18:03:05
Having two issues.
Insteon API is supposed to support Oauth version 2, but when I try to authenticate, I'm getting:
Error: it was not possible to open the OAuth access token URL: it was not specified the protocol type argument

I defined:
"dialog_url": "https://connect.insteon.com/api/v2/oauth2/auth?client_id={CLIENT_ID}&state={STATE}&response_type=code&redirect_uri={REDIRECT_URI}",
"request_token_url": "https://connect.insteon.com/api/v2/oauth2/token",

Documentation: https://insteon.docs.apiary.io/

The other issue that I'm having, is I'm trying to develop command line scripts, not code that is used under a Webserver, and this generates some other errors:

PHP Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/rom/insteon/insteon.php:6) in /home/rom/insteon/oauth_client/oauth_client.php on line 1500
PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/rom/insteon/insteon.php:6) in /home/rom/insteon/oauth_client/oauth_client.php on line 1500
PHP Notice: Undefined index: HTTP_HOST in /home/rom/insteon/oauth_client/oauth_client.php on line 1358
PHP Notice: Undefined index: REQUEST_URI in /home/rom/insteon/oauth_client/oauth_client.php on line 1358

Looks like the library wasn't designed to be used by command line code.

  2. Re: Insteon API support   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2020-02-02 23:20:03 - In reply to message 1 from Fred Wittekind
It seems that at a certain point an URL is passed to send a HTTP request to a server but that URL is malformed due to missing the http or https URL scheme value.

Can you please set the class debug variable to true and then execute that script? Then get the debug output and paste it in your response text to this message. Make sure that you are removing or obfuscating any sensitive data that should not be disclosed to the public for privacy reasons.

The other issue is tricky because you cannot your OAuth tokens other way than via Web pages. Those error messages are due to cookies that cannot be set in the console because there is no Web browser.

I think the best solution for you on that is to have some Web scripts just to get the first OAuth token values using the file_oauth_client_class instead because it uses files to store token values instead of cookies. Then you can make API calls using the same class.

  3. Re: Insteon API support   Reply   Report abuse  
Picture of Fred Wittekind Fred Wittekind - 2020-02-03 03:23:43 - In reply to message 2 from Manuel Lemos
I was hoping to use
insteon.docs.apiary.io/#reference/a ...

Which allows passing the username and password, so It doesn't require password entry in a web browser. I think using this method the session stuff shouldn't be needed.

Debug output:
OAuth client: Checking if OAuth access token was already retrieved from
PHP Warning: session_start(): Cannot send session cookie - headers already sent by (output started at /home/rom/insteon/insteon.php:6) in /home/rom/insteon/oauth_client/oauth_client.php on line 1500
PHP Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/rom/insteon/insteon.php:6) in /home/rom/insteon/oauth_client/oauth_client.php on line 1500
OAuth client: A valid access token is not available
OAuth client: Getting the access token using the username and password
PHP Notice: Undefined index: HTTP_HOST in /home/rom/insteon/oauth_client/oauth_client.php on line 1358
PHP Notice: Undefined index: REQUEST_URI in /home/rom/insteon/oauth_client/oauth_client.php on line 1358
OAuth client: Accessing the OAuth access token at
OAuth client: Error: it was not possible to open the OAuth access token URL: it was not specified the protocol type argument
Error: it was not possible to open the OAuth access token URL: it was not specified the protocol type argument

  4. Re: Insteon API support   Reply   Report abuse  
Picture of Manuel Lemos Manuel Lemos - 2020-02-03 18:21:49 - In reply to message 3 from Fred Wittekind
OAuth is just to let applications access APIs in behalf of a user that previously authorized your access. That is why I suggested to obtain the token on a Web page using the file_oauth_client_class and then you can access the API without any password, as this class gets you the token to perform authenticated API accesses.

But if you have a user name and password that you can use to access the API, you can just perform direct HTTP requests using regular PHP functions or the HTTP client class that this OAuth class already uses.