小编Tan*_*was的帖子

如何使用API​​通过PHP获取instagram照片?

最近两天,我试图通过原始PHP显示来自Instagram个人资料的照片。但是我遇到了这些错误。

Notice: Trying to get property of non-object in E:\xampp7\htdocs\instagram\index.php on line 29

Warning: Invalid argument supplied for foreach() in E:\xampp7\htdocs\instagram\index.php on line 29
Run Code Online (Sandbox Code Playgroud)

我从instagram API 创建了正确的身份验证。我请求的API clients access有效(clientId, userId, accessToken)。当我用PHP失败时,我尝试使用JavaScript插件instafeedjs。现在,它运行良好。这是我的PHP代码,如下所示:

<body>
<?php
function fetchData($url){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 20);
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
    }

    $result = fetchData("https://api.instagram.com/v1/users/3550421370/media/recent/?access_token=MY_VALID_ACCESS_TOKEN_IS_HERE");

    $result = json_decode($result);
    foreach ($result->data as $post) {
    if(empty($post->caption->text)) {
    // Do Nothing
    }
    else { …
Run Code Online (Sandbox Code Playgroud)

php instagram instagram-api

2
推荐指数
2
解决办法
2万
查看次数

以php double数据类型格式获取价值

$td = 4.0;
echo $td;
Run Code Online (Sandbox Code Playgroud)

输出为4;但是我想要双数据类型的实数(4.0)。

php type-conversion

-1
推荐指数
1
解决办法
927
查看次数

标签 统计

php ×2

instagram ×1

instagram-api ×1

type-conversion ×1