我正在尝试将镜像 api 实现到 wordpress 站点中,但是在我登录并进行身份验证后,该站点尝试加载大约 30 秒,然后说存在重定向循环失败。
我实现镜像 api 的方式是创建一个包含 oauth 和诸如此类所需的所有 php 的模板,然后使用 builder 进行布局、内容等。我认为这可能是 wordpress 的问题,但我不想要放弃希望。
谢谢您的帮助
编辑:这是我在我的 wordpress 页面模板中使用的代码。
<?php
/*
Template Name: Glass
*/
require_once $_SERVER['DOCUMENT_ROOT'].'/glass/config.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/glass/mirror-client.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/glass/google-api-php-client/src/Google_Client.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/glass/google-api-php-client/src/contrib/Google_MirrorService.php';
require_once $_SERVER['DOCUMENT_ROOT'].'/glass/util.php';
$client = get_google_api_client();
$message= "";
$subscriptionId;
if(isset($_GET['message']))
$message = $_GET['message'];
if (!isset($_SESSION['userid']) || get_credentials($_SESSION['userid']) == null) {
header('Location: ' . $base_url . '/oauth2callback.php');
exit;
} else {
$client->setAccessToken(get_credentials($_SESSION['userid']));
}
// A glass service for interacting with the Mirror API
$mirror_service = new Google_MirrorService($client);
$subscriptions = $mirror_service->subscriptions->listSubscriptions();
$timeline_subscription_exists = false;
foreach ($subscriptions->getItems() as $subscription) {
if ($subscription->getId() == 'timeline') {
$timeline_subscription_exists = true;
$subscriptionId = $subscription->getId();
}
}
switch ($_GET['operation']){
case 'createSubscription':
$message = subscribe_to_notifications($mirror_service, "timeline",
$_SESSION['userid'], "https://mirrornotifications.appspot.com/forward? url=".$base_url."/notify.php");
//Refresh Page
$mHeader = 'Location: ' . $base_url;
if($message != "")
$mHeader = $mHeader . '?message='.$message;
header($mHeader); exit;
break;
case 'deleteSubscription':
$message = $mirror_service->subscriptions->delete($subscriptionId);
//Refresh Page
$mHeader = 'Location: ' . $base_url;
if($message != "")
$mHeader = $mHeader . '?message='.$message;
header($mHeader);
exit;
break;
case 'refreshCard':
createControlCard($client);
header('Location: ' . $base_url);
exit;
break;
case 'refreshInfo':
generateInfoCards($client);
header('Location: ' . $base_url);
exit;
break;
}
get_header(); ?>
<div id="content" class="widecolumn">
<div id="main">
</div>
</div>
<?php get_footer(); ?>