Announcement

#1 2021-08-27 11:26:27

chris_fang
Member
2021-08-18
4

Making json Interface

Hello,

I'm writing a plugin
This plugin has a task function
I want to use a post or get request through a third-party service,
Then  want to ask how to adjust the URL to return the data type json?

Code:

if (isset($_POST))
{
    echo 'json';
}

Thank you


Piwigo 12.0.0beta2
WINNT
PHP: 7.3.4  [2021-08-27 17:14:57]
MySQL: 5.7.26 [2021-08-27 17:14:57]
GD bundled (2.1.0 compatible)

Offline

 

#2 2021-08-27 11:37:53

chris_fang
Member
2021-08-18
4

Re: Making json Interface

Here I'm just going to imitate something like this
Write the template file to $template

Code:

if (isset($_POST))
{
    echo 'json';
    # or 
    array_push($page['infos'], 'seed successful');
}

$template->set_filename('plugin_admin_content', dirname(__FILE__) . '/template/upload.tpl');
$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');

But I don't think that's what I want

Offline

 

#3 2021-08-28 03:59:08

chris_fang
Member
2021-08-18
4

Re: Making json Interface

Can you give me some hints? I really want to know
When I asked for the login interface, I got the correct JSON format
But when I go through the url of the plugin, I get the HTML page
Can you give me some hints on the internal functions
Or some demo on Github

Code:

$url = 'http://127.0.0.1/ws.php?format=json'
$form_data = {
    'method': 'pwg.session.login',
    'username': 'name',
    'password': 'pass',
}

$results = "requests url" 

results:
{"stat":"ok","result":true}

But

Code:

# plugin-ImageAcquisition-upload  
# This is my custom plugin path
url = 'http://192.168.31.53/admin.php?page=plugin-ImageAcquisition-upload'

$form_data = {
    'submit': 'submit',
}

$results = "requests url" 

results:
<!DOCTYPE html>

I'm not particularly familiar with this, so if anyone can guide me, I'd appreciate it

Offline

 

#4 2021-08-28 08:10:54

nicolas
Former Piwigo Team
2004-12-30
1232

Re: Making json Interface

I read several times your messages and I'm not sure to understand what you want nor what you try to do. Can you explain it another time ?

I take my chance in any case.
WIth your plugin, you can add your own methods to the Piwigo API using ws_add_methods event handler. Of course theses methods can return json if you want.

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2024 · Contact