Avatar

How to get records from Kintone app into my localhost php program

Hima Bindu Y

I am using OAUTH clients. In one of my php page I set a link and set this as href

https://{subdomain}.kintone.com/oauth2/authorization
  ?client_id={your_client_id}&redirect_uri={your_redirect_url}&state=state1&response_type=code&scope=k%3Aapp_record%3Aread

I set my redirect_uri as http://localhost/kintone.php. When I click on this link, I get an error saying "The redirect_uri parameter is not valid". I also see a code and id values on the same page. What could be the error, can anyone please point it out to me. 

Thanks

Follow 3 followers
1

7 comments

Avatar
Yuzo Arai 1 vote
Hello Hima,

Have you filled out the redirect endpoint on the kintone side?
The setting is at the following:
https://(subdomain).kintone.com/admin/oauth/client/add

Also, to let you know, the URI needs to be in the "HTTPS" protocol,
so can you check that out in case if you already did set up the redirect endpoint on the kintone side?

Kintone Developer Program - How to add OAuth clients
1
Comment actions Permalink
Avatar
Hima Bindu Y 0 votes

No, I was setting the redirect_uri to my localhost. I set the redirect_uri as https://localhost/display_records.php. I want to get the authentication code and then want to get the records from a Kintone app and display on my php page. Here is the scenario. 

1. I want to create a php page to have a form, which is accessible to public, once the form is submitted, I want to get the data and put it into kintone app. 

2. I want to read from that kintone app and display all the data onto my php page, which should be public.

How to achieve this please?

I am trying to use curl_get() in php as well, but it still complains wrong redirect_uri. Please help.

0
Comment actions Permalink
Avatar
Sean Tachibana 0 votes
Hello Hima,
 
As you mentioned in your first post,
 
>I also see a code and id values on the same page.
 
Could you please send us that error code and the ID value?
I will be glad to help.
 
Thanks,
Sean
0
Comment actions Permalink
Avatar
Hima Bindu Y 0 votes

Hi Sean,

Here is the error that I see, with code and id values. 

Also I noticed that this time when I run the code, it takes me to login screen after I login it fails with this error.

In my Kintone account I created an OAuth client under Integrations. I also set myself as allowed user. When I click on my name in my account settings under Integrations tab, I notice that against this OAuth Client it shows my status as "Inactive". Could that be the reason for it to take me to the login page? How to set it to Active?

Any help on this is greatly appreciated. I also attached my code at the bottom.

 

<?php
If(!isset($_GET['code']))
{
//Initialize a CURL session
$ch=curl_init();

//From URL to get webpage contents
$url="https://{sudomain_name}.kintone.com/oauth2/authorization?client_id={Client_ID}&redirect_uri=http%3A%2F%2Flocalhost%2Fcurlget.php&state=state1&response_type=code&scope=k%3Aapp_record%3Aread";

curl_setopt($ch, CURLOPT_POST, 1);

//grab URL and pass it to the variable
curl_setopt($ch, CURLOPT_URL, $url);

curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

//Execute and get result
$result = curl_exec($ch);
if(!$result)
{
die("Connection Failure");
}
else
{
echo $result;
}
curl_close($ch);
}
else
{
echo $_GET['code'];
}

?>

0
Comment actions Permalink
Avatar
Yuzo Arai 0 votes

Hey Hima,

> I notice that against this OAuth Client it shows my status as "Inactive".

This is possibly the reason why you see the error upon logging in.
You should be able to change between active and inactive by clicking on the button
next to the "Set allowed users" for the client.

But I assume that's not possible, I guess?
Can I see how the setting page looks on your side?

0
Comment actions Permalink
Avatar
Sean Tachibana 0 votes

Hello Hima,

 

It depends on the setting on the OAuth side, so it is difficult to determine the error just by looking at the code at the moment
but, the "http" protocol was specified in redirect_uri.

 

redirect_uri=http%3A%2F%2Flocalhost%2Fcurlget.php

 

A URL starting with "http" is specified, but since only "https" can be specified as a redirect endpoint for OAuth authentication.
So, the error might be caused by that.

 

Also, I do not entirely understand the part,
>When I click on my name in my account settings under Integrations tab, I notice that against this
>OAuth Client it shows my status as "Inactive". Could that be the reason for it to take me to the login page?
>How to set it to Active?

 

Could you please check the following for us?

・Does the URL specified in the redirect_url match the URL specified in the redirect endpoint of OAuth authentication?
If not, please match it.

・If the OAuth client is not available; please check if it is enabled by clicking on it.
If not, please send the screenshot of the "Inactive" screen to see the current status.

・Please, send us a screenshot of your Add OAuth Client settings screen.

 

Hopefully, this helps.

Sean

0
Comment actions Permalink
Avatar
Hima Bindu Y 1 vote

Thank you Sean and Yuzo for responding promptly. Actually I found this resource and this worked. 

https://github.com/ochi51/cybozu-http

The below given part is not clear in the documentation as to where to put the line of code. I tried to do it with composer but it threw me error. Later I found out after many attempts that this line of code will go into your trial php program file, just above the quick start piece of code. I hope this helps anyone else who is trying to attempt api calls with PHP.

After installing, you need to require Composer's autoloader:

    require 'vendor/autoload.php';
1
Comment actions Permalink