返回错误状态代码“的Eventbrite API的PHP代码:404

rdrgkggo  于 2023-03-16  发布在  PHP
关注(0)|答案(1)|浏览(141)

我尝试通过令牌和组织ID获取组织的所有事件,但我获取
{“状态代码”:404,“错误描述”:“您请求的路径不存在。",“错误”:“未找到”}
这是我的PHP代码,任何帮助将不胜感激。

<?php
//error_reporting(E_ALL);
ini_set('display_errors', '1');
$token = 'XYZ123456XYZ';
$url = 'https://www.eventbriteapi.com/v3/organizations/123456789/events=' . $token;

// Initialize cURL
$ch = curl_init();

// Set the cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// Execute the cURL request and get the response
$response = curl_exec($ch);

// Print the raw response to the console
echo '<pre>';
print_r($response);
echo '</pre>';

// Close the cURL session
curl_close($ch);

// Parse the JSON response
$events = json_decode($response, true);

// Check for errors
if (isset($events['error'])) {
    echo 'Error: ' . $events['error_description'];
} else {
    // Loop through the events and display their information
    foreach ($events['events'] as $event) {
        echo '<h2>' . $event['name']['text'] . '</h2>';
        echo '<p>' . $event['description']['text'] . '</p>';
        echo '<p>' . $event['start']['local'] . '</p>';
        echo '<p>' . $event['end']['local'] . '</p>';
        echo '<p>' . $event['venue']['name'] . '</p>';
        echo '<hr>';
    }
}

我试过改变端点的网址值,尝试与和没有组织的ID,但似乎没有什么工作。它应该显示所有的事件名称,描述,开始时间等。

zpgglvta

zpgglvta1#

我又看了一遍文档,发现我使用的链接已经过时了,我把答案留在这里,让其他人很容易找到。
这是获取专用令牌的链接
https://www.eventbrite.com/platform/docs/authentication#get-a-private-token
https://www.eventbrite.com/platform/api-keys

<?
 //error_reporting(E_ALL);
//ini_set('display_errors', '1');

$token = 'enterurtokenhere';
$url = 'https://www.eventbriteapi.com/v3/organizations/{enteruridhere}/events/?status=live';

// Initialize cURL
$ch = curl_init();

// Set the cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Authorization: Bearer ' . $token
));

// Execute the cURL request and get the response
$response = curl_exec($ch);

// Print the raw response to the console
echo '<pre>';
print_r($response);
echo '</pre>';

// Close the cURL session
curl_close($ch);

// Parse the JSON response
$events = json_decode($response, true);

// Check for errors
if (isset($events['error'])) {
    echo 'Error: ' . $events['error_description'];
} else {
    // Loop through the events and display their information
    foreach ($events['events'] as $event) {
        echo '<h2>' . $event['name']['text'] . '</h2>';
        echo '<p>' . $event['description']['text'] . '</p>';
        echo '<p>' . $event['start']['local'] . '</p>';
        echo '<p>' . $event['end']['local'] . '</p>';
        echo '<p>' . $event['venue']['name'] . '</p>';
        echo '<hr>';
    }
}
?>

相关问题