gpt4 book ai didi

oauth - 如何避免 fatal error : Uncaught OAuthException when using cron job

转载 作者:行者123 更新时间:2023-12-01 05:29:51 26 4
gpt4 key购买 nike

嗨,希望有人可以帮助解决这个问题。我已经构建了一个生日提醒应用程序,它获得了通常的权限,包括离线访问等。

该应用程序需要在我的服务器上运行每日 cron 作业。
当我运行 cron 文件时,收到以下错误

fatal error :未捕获的 OAuthException:无效的 OAuth 访问 token 签名。在 1140 行的 blah/base_facebook.php 中抛出;

错误是否有一个共同的原因,我是否做错了任何突出的事情,我是否应该显示更多代码以从人们那里获得帮助?

下面是导致错误的行。我的代码在第 1140 行结束;

<?php

$name = 'api';
if (isset($READ_ONLY_CALLS[strtolower($method)])) {
$name = 'api_read';
} else if (strtolower($method) == 'video.upload') {
$name = 'api_video';
}
return self::getUrl($name, 'restserver.php');
}

protected function getUrl($name, $path='', $params=array())
{
$url = self::$DOMAIN_MAP[$name];
if ($path) {
if ($path[0] === '/') {
$path = substr($path, 1);
}
$url .= $path;
}
if ($params) {
$url .= '?' . http_build_query($params, null, '&');
}

return $url;
}

protected function getCurrentUrl() {
if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$protocol = 'https://';
}
else {
$protocol = 'http://';
}
$currentUrl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$parts = parse_url($currentUrl);

$query = '';
if (!empty($parts['query'])) {
// drop known fb params
$params = explode('&', $parts['query']);
$retained_params = array();
foreach ($params as $param) {
if ($this->shouldRetainParam($param)) {
$retained_params[] = $param;
}
}

if (!empty($retained_params)) {
$query = '?'.implode($retained_params, '&');
}
}

// use port if non default
$port =
isset($parts['port']) &&
(($protocol === 'http://' && $parts['port'] !== 80) ||
($protocol === 'https://' && $parts['port'] !== 443))
? ':' . $parts['port'] : '';

// rebuild
return $protocol . $parts['host'] . $port . $parts['path'] . $query;
}

protected function shouldRetainParam($param) {
foreach (self::$DROP_QUERY_PARAMS as $drop_query_param) {
if (strpos($param, $drop_query_param.'=') === 0) {
return false;
}
}

return true;
}

protected function throwAPIException($result) {
$e = new FacebookApiException($result);

?>

CRON.php
<?php
require_once("src/facebook.php");
include("custom.php");

set_time_limit(0);

$config = array();
$config['array'] = $appID;
$config['secret'] = $appSecret;
$facebook = new Facebook($config);

$day = abs(date("j"));
$month = abs(date("n"));

$result = mysql_query("SELECT uid, uid2, name2 FROM birthdays WHERE birthmonth = '$month' AND birthday = '$day'");
while(($row = mysql_fetch_assoc($result)) && mysql_num_rows($result)) {
$link = $hostURL.'post.php?uid='.$row['uid'].'&uid2='.$row['uid2'];
$facebook->api('/'.$row['uid'].'/feed', 'POST',
array(
'link' => $link,
'from' => '299185790135651',
'picture' => $hostURL.'image.php?id='.$row['uid2'],
'name' => 'Send Cake',
'message' => 'It\'s '.$row['name2'].'\'s birthday today! Send them a virtual cake!',
'caption' => 'Sponsored by Intercake Ltd'
));
}

?>

还有……什么是“来自”=>“299185790135651”,?

想检查我的开发人员是否在此处输入了正确的数字。谢谢

最佳答案

处理此问题的最佳方法是使用 try...catch陈述。如下:

try {
// some code that calls Facebook
} catch ( Exception $e ) {
// $e will contain the error - do what you want with it here
// e.g. log it or send an email alert etc.
}
'from' => '299185790135651'是将消息发布到 Feed 的用户/页面 ID。在这种情况下,它指向 Test Facebook Page .

关于oauth - 如何避免 fatal error : Uncaught OAuthException when using cron job,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11839544/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com