gpt4 book ai didi

javascript - 使用 PHP cURL 的 X-Insta-Forwarded-For 错误 Instagram API

转载 作者:行者123 更新时间:2023-12-03 10:01:11 26 4
gpt4 key购买 nike

我正在尝试使用此 api 和关系的 POST 方法在 Instagram 上发帖。

这是我正在使用的端服务器代码:

<?php

$url = "https://api.instagram.com/v1/users/<user>/relationship";
$ips= (isset($_SERVER['SERVER_ADDR'])) ? $_SERVER['SERVER_ADDR'] : gethostbyname(gethostname());
$signature = (hash_hmac('sha256', $ips, '<secret>', false));

$join = join('|', array($ips, $signature));

$headerData = array('Accept: application/json');

$headerData[] = 'X-Insta-Forwarded-For: ' .$join;

$fields = array(
'access_token' => '<access_token>',
'action' => 'follow'
);

$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
//curl_setopt($ch, CURLOPT_HTTPHEADER, $headerData);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

// grab URL and pass it to the browser
$result = curl_exec($ch);
$error = curl_error($ch);
// close cURL resource, and free up system resources
curl_close($ch);

print_r($result);
?>

如您所见,我已注释掉此行:

//curl_setopt($ch, CURLOPT_HTTPHEADER, $headerData);

因为据我所知,要使用 cURL 发布到 Instagram,我只需要一个有效的 access_token,但 Instagram 向我返回此错误:

{"code": 403, "error_type": "OAuthForbiddenException", "error_message": "Invalid header: X-Insta-Forwarded-For is required for this operation"}

我明白这意味着什么,但我的问题是,是否有人尝试过类似的操作,而没有在 Instagram API 上注册应用程序并使用在互联网上找到的外部 access_token?

最佳答案

您正在使用的 access_token 所属的应用可能已激活此签名 header POST 限制(“强制签名 header ”)。

转到https://instagram.com/developer/clients/manage/要创建或管理您的应用程序,请单击编辑应用程序,然后单击安全选项卡。您应该看到下面的页面。 强制签名请求(新的、更好的签名方法)和强制签名 header (旧方法,将于 9 月 1 日弃用)是避免滥用被盗信息的方法访问 token 。

如果选中强制签名 header ,则在没有X-Insta-Forwarded-For的情况下,您无法向 Instagram API 发布任何内容。正如如果选中“强制签名请求”,您就无法在没有 sig 参数的情况下向 API 发出请求。

我建议您学习new signed request method观察那些Instagram API secure requests considerations

Instagram App Security Tab

关于javascript - 使用 PHP cURL 的 X-Insta-Forwarded-For 错误 Instagram API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30592872/

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