dongyuan2388 2016-10-28 19:31
浏览 39
已采纳

重力形式WebAPI(GET Forbidden - PHP)

I'm trying to use the Wordpress Gravity Forms Web API to get entries from a form and simply display them. I have this so far, I have made sure to check my API Key and Private Key are correct, with no luck. No matter what I do, I get a Forbidden response.

Here is my code, is there something I'm doing wrong that you can notice?

<?php
$api_key = 'here';
$private_key = 'here';
$method  = 'GET';
$endpoint = 'http://website.co.uk/gravityformsapi/';
//$route = 'entries';
$route = 'forms/1/entries/';
$expires = strtotime('+60 mins');
$string_to_sign = sprintf('%s:%s:%s:%s', $api_key, $method, $route, $expires);
$sig = calculate_signature($string_to_sign, $private_key);

$api_call = $endpoint.$route.'?api_key='.$api_key.'&signature='.$sig.'&expires='.$expires;


$ch = curl_init($api_call);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

print_r($response);

echo $api_call;
function calculate_signature($string, $private_key) {
    $hash = hash_hmac("sha1", $string, $private_key, true);
    $sig = rawurlencode(base64_encode($hash));
    return $sig;
}
?>

Thanks!

  • 写回答

1条回答 默认 最新

  • doue2666 2016-10-29 08:21
    关注

    The user account in the impersonation settings needs to have the appropriate capability, in this case gravityforms_view_entries. You may need to explicitly assign that capability to the role.

    Also, try removing the trailing slash from the route.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000
  • ¥30 ppOCRLabel导出识别结果失败
  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿