为什么 PHP 在使用 Instagram PHP API 时不保存会话?
我正在尝试使用此处的 php 库创建一个 Instagram 应用程序(文件不是很长,不用担心):
我正在尝试使用 OAUTH 来授权用户,它工作得很好,并且授权的(当前用户)可以看到他的信息(如图像、姓名)等等...),但是当我刷新页面时,一切都会消失,我只剩下空白数据,这是代码 -
// Instantiate the API handler object
$instagram = new Instagram($config);
$accessToken = $instagram->getAccessToken();
$_SESSION['InstagramAccessToken'] = $accessToken;
$instagram->setAccessToken($_SESSION['InstagramAccessToken']);
$userinfo = $instagram->getUser($_SESSION['InstagramAccessToken']);
// After getting the response, let's iterate the payload
$ures = json_decode($userinfo, true);
该代码第一次运行正常,但是当您刷新页面时,不会检索信息,这只能意味着一件事,即会话或 cookie 未正确设置,这就是 getUser 方法未检索信息的原因,
$userinfo = $instagram->getUser($_SESSION['InstagramAccessToken']);
请您解释一下这个问题,我已经尝试了 4 个小时!
I'm trying to create a instagram app using the php library which is here(its not very long file, don't worry):
I'm trying to authorise the user by using OAUTH, which works perfectly, and the authorised(current user) can see his information(like Image, name etc...), but when i refresh the page it all goes and I'm left with blank data, heres the code -
// Instantiate the API handler object
$instagram = new Instagram($config);
$accessToken = $instagram->getAccessToken();
$_SESSION['InstagramAccessToken'] = $accessToken;
$instagram->setAccessToken($_SESSION['InstagramAccessToken']);
$userinfo = $instagram->getUser($_SESSION['InstagramAccessToken']);
// After getting the response, let's iterate the payload
$ures = json_decode($userinfo, true);
this code works fine the first time round, but when you refresh the page, the information is not being retrieved, and that could only mean one thing, that the session or the cookie is not set properly and thats why the getUser method is not retrieving the information,
$userinfo = $instagram->getUser($_SESSION['InstagramAccessToken']);
please can you shed some light into this problem, i have been trying for 4 hours!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的每个请求中,您都通过这一行覆盖当前会话数据:
最有可能的是它应该是这样的:
On each your request you overwrite current session data with nothing by this line:
Most likely this is how it should look like: