调用Pho.to API

问题描述 投票:0回答:3

我尝试调用 Pho.to API 来编辑照片,每次尝试 POST 时都会遇到相同的错误。我已经两次和三次检查了我的

app_id
和我的
key
,但我不知道我做错了什么。我目前正在使用 ARC Chrome 扩展来调用此 API,因此我什至还没有开始编写该部分的代码,我只是尝试从 API 获取真实的响应以确保它能够正常工作。

我尽可能遵循他们文档中的说明。以下是参考链接:http://developers.pho.to/documentation/sending-requests

这是我的 API 调用:

http://opeapi.ws.pho.to/addtask?APP_ID=<my-app-id>&KEY=<my-key>&SIGN_DATA=910ceb5bdb238b9248a34cce8b29ba64d5f239df

这是我得到的回复(不要被 200 欺骗):

Status: 200 OK

<?xml version="1.0" ?>
<image_process_response>
    <status>SecurityError</status>
    <err_code>614</err_code>
    <description>Error in POST parameters: one or more parameters (DATA , SIGN_DATA or APP_ID) are empty</description>
</image_process_response>

这是我用来为

SIGN_DATA
创建 SHA1 的 PHP 代码:

<?php
    echo hash_hmac('SHA1', '<image_process_call><lang>en</lang><image_url order="1">http://www.w3schools.com/html/pic_mountain.jpg</image_url><methods_list><method order="1"><name>desaturation</name></method><method order="2"><name>cartoon</name><params>fill_solid_color=1;target_color=(255,255,255);border_strength=20;border_width=3</params></method></methods_list><result_format>png</result_format><result_size>600</result_size></image_process_call>','<my-key>');
?>

这是上面的 XML,为了便于阅读而进行了格式化:

<image_process_call>
    <lang>en</lang>
    <image_url order="1">http://www.w3schools.com/html/pic_mountain.jpg</image_url>
    <methods_list>
        <method order="1">
            <name>desaturation</name>
        </method>
        <method order="2">
            <name>cartoon</name>
            <params>fill_solid_color=1;target_color=(255,255,255);border_strength=20;border_width=3</params>
        </method>
    </methods_list>
    <result_format>png</result_format>
    <result_size>600</result_size>
</image_process_call>

如有任何帮助,我们将不胜感激。

php android sha1
3个回答
5
投票

所以我明白出了什么问题。这是我为其他可能遇到此 api 类似问题的人提供的详细解决方案(无论平台如何):

问题的一部分(正如 @u_mulder 指出的)是

DATA
需要与
SIGNED_DATA
一起发送,以便 SHA1 可以在另一端解码。

解决我的问题的另一部分是删除

<lang>en</lang>
。无论出于何种原因,返回
Error 613: Invalid SIGN_DATA parameter.
英语无论如何都是默认语言,所以这是不必要的。

解决这些问题后,这是我的最终网址:

http://opeapi.ws.pho.to/addtask/?app_id=<my-app-id>&key=<my-key>9&sign_data=e456c393d11797c1a2945a85dd49ba2208cc66de&data=%3Cimage_process_call%3E%3Cimage_url+order%3D%221%22%3Ehttp%3A%2F%2Fwww.heroesandheartbreakers.com%2Fimages%2Fstories%2Fblogarticles%2F2016%2FJanuary2016%2FTV-Recap-Arrow-4x11-Olicity-is-home-470.jpg%3C%2Fimage_url%3E%3Cmethods_list%3E%3Cmethod+order%3D%221%22%3E%3Cname%3Ecartoon%3C%2Fname%3E%3Cparams%3Efill_solid_color%3D1%3Btarget_color%3D%28255%2C255%2C255%29%3Bborder_strength%3D20%3Bborder_width%3D1%3C%2Fparams%3E%3C%2Fmethod%3E%3C%2Fmethods_list%3E%3Cresult_format%3Epng%3C%2Fresult_format%3E%3Cresult_size%3E1500%3C%2Fresult_size%3E%3C%2Fimage_process_call%3E

请注意,url 已编码。这可能是必要的,也可能不是必要的,我只是将其编码以确保安全。

返回:

<?xml version="1.0" ?>
<image_process_response>
    <request_id>010afc13-6bba-44dd-b278-4f3bd1e41946</request_id>
    <status>OK</status>
    <description />
    <err_code>0</err_code>
</image_process_response>

我现在可以使用

request_id
来获取编辑后的图像的 url:

http://opeapi.ws.pho.to/getresult?request_id=010afc13-6bba-44dd-b278-4f3bd1e41946

返回以下 xml:

<image_process_response>
    <request_id>010afc13-6bba-44dd-b278-4f3bd1e41946</request_id>
    <status>OK</status>
    <result_url>http://worker-images.ws.pho.to/i1/3BCB160A-691A-458B-9161-67AFA8A9EAA0.png</result_url>
    <result_url_alt>http://worker-images.ws.pho.to.s3.amazonaws.com/i1/3BCB160A-691A-458B-9161-67AFA8A9EAA0.png</result_url_alt>
    <nowm_image_url>http://worker-images.ws.pho.to/i1/3BCB160A-691A-458B-9161-67AFA8A9EAA0.png</nowm_image_url>
</image_process_response>

所以最终编辑图像的网址是http://worker-images.ws.pho.to/i1/3BCB160A-691A-458B-9161-67AFA8A9EAA0.png(我相信链接会在24小时后过期)

我们就完成了!

如果您想了解我如何在简单的 Android 应用程序中实现此 api,请参阅以下 github 链接:https://github.com/youravgjoe/ColoringPageGenerator

之前:

之后:


0
投票

对我来说,错误已通过以下方式修复:(A) 确保使用 SHA1 而不是 SHA256(我自己的错误)和 (B) 由于某种原因,sign_data 值必须小写。


0
投票

删除 XML 中的所有新行 (Enter),然后重试。

<image_process_call>
    <lang>en</lang>
    <image_url order="1">http://www.w3schools.com/html/pic_mountain.jpg</image_url>
    <methods_list>
        <method order="1">
            <name>desaturation</name>
        </method>
        <method order="2">
            <name>cartoon</name>
            <params>fill_solid_color=1;target_color=(255,255,255);border_strength=20;border_width=3</params>
        </method>
    </methods_list>
    <result_format>png</result_format>
    <result_size>600</result_size>
</image_process_call>

<image_process_call><lang>en</lang><image_url order="1">http://www.w3schools.com/html/pic_mountain.jpg</image_url><methods_list><method order="1"><name>desaturation</name></method><method order="2"><name>cartoon</name><params>fill_solid_color=1;target_color=(255,255,255);border_strength=20;border_width=3</params></method></methods_list><result_format>png</result_format><result_size>600</result_size></image_process_call>

© www.soinside.com 2019 - 2024. All rights reserved.