PHP:使用Podio API验证webhook

时间:2013-06-05 04:03:19

标签: php webhooks podio

我正在使用Podio PHP API,我想在此处验证webhook:https://developers.podio.com/examples/webhooks

我的服务器上有一个测试脚本:http://qvido.se/api/podio/ValidateHook.php,其中包含以下代码:

<?php
    require_once('Depend/PodioAPI.php');
    require_once('Depend/config.php');

    error_log("validate triggerd");

    // Setup client
    Podio::setup($client_id, $client_secret);

    // Turn on debugging
    Podio::$debug = true;

    // Authenticate the application
    Podio::authenticate('app', array('app_id' => MY_APP_ID, 'app_token' => 'MY_APP_TOKEN'));

    switch ($_POST['type']) {
        case 'hook.verify':
            // Validate the webhook
          PodioHook::validate($_POST['hook_id'], array('code' => $_POST['code']));
        case 'item.create':
            // Do something. item_id is available in $_POST['item_id']
        case 'item.update':
            // Do something. item_id is available in $_POST['item_id']
        case 'item.delete':
            // Do something. item_id is available in $_POST['item_id']
    }
?>

在Podio界面中点击Verfiy时,它似乎没有向我的脚本发送$_POST请求。我打开了调试模式,但podio.log文件中没有记录任何内容。相反,它在尝试将$_POST请求发送到我的脚本时显示302错误代码。

我认为根本不会调用我的脚本。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

假设所有其他变量都已正确定义,静态Podio :: authenticate()方法仍然存在错误。

只需从MY_APP_TOKEN中删除引号:

所以

    Podio::authenticate('app', array('app_id' => MY_APP_ID, 'app_token' => 'MY_APP_TOKEN'));

最好是

   Podio::authenticate('app', array('app_id' => MY_APP_ID, 'app_token' => MY_APP_TOKEN));

干杯!