【发布时间】:2023-04-04 03:47:02
【问题描述】:
我正在尝试使用此 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?
【问题讨论】:
-
“仅用于学术目的” 没关系,如果它是非法的,它不属于 SO。
标签: javascript php curl instagram instagram-api