dongsha2792 2011-11-20 22:02
浏览 124
已采纳

来自twitter API的“无法验证您”错误

I'm using Abhraham's twitter API library.

My index.php

<?php
ob_start();
session_start();
require_once 'twitteroauth/twitteroauth.php';
require_once 'twitteroauth/OAuth.php';
define("CONSUMER_KEY", "");
define("CONSUMER_SECRET", "");
$to = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$tok = $to->getRequestToken("http://mydoamin.com/twitter/redirect.php");
$request_link = $to->getAuthorizeURL($tok);
$_SESSION['oauth_access_token']= $tok['oauth_token'];
$_SESSION['oauth_access_token_secret'] = $tok['oauth_token_secret'];
header("Location: $request_link");
exit;
?>

My redirect.php

<?php
ob_start();
session_start();
require_once 'twitteroauth/twitteroauth.php';
require_once 'twitteroauth/OAuth.php';
define("CONSUMER_KEY", "");
define("CONSUMER_SECRET", "");

$to=new TwitterOAuth(CONSUMER_KEY,CONSUMER_SECRET,$_SESSION['oauth_access_token'],$_SESSION['oauth_access_token_secret']);
$content = $to->get('account/verify_credentials');
var_dump($content);
?>

But I dont understant why I'm getting "Could not authenticate you" on the redirect.php page

  • 写回答

1条回答 默认 最新

  • douciwang6819 2011-11-21 15:58
    关注

    I think this doesn't work because you cannot put $tok directly in the getAuthrorizeURL() function:

    $tok = $to->getRequestToken("http://mydoamin.com/twitter/redirect.php");
    $request_link = $to->getAuthorizeURL($tok);
    

    You need to extract the token from $tok['oauth_token']:

    $tok = $to->getRequestToken("http://mydoamin.com/twitter/redirect.php");
    $request_link = $to->getAuthorizeURL($tok['oauth_token']);
    

    Let me know if this fixes it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?