dongwei1234 2010-12-23 17:51
浏览 52

PHP OAuth Twitter

I have created a twitter app which I am using to post tweets. The problem that I am not able to resolve is everytime I have to allow access to my application.

so lets say I need to tweet three messages, so all the three times I have to allow access to my app.

I just need that once user has allowed access to my app, next time he should only be asked to allow acces is that when he/she relogins.

Here's my code that I am using

  Share content on twitter";

include 'lib/EpiCurl.php';
include 'lib/EpiOAuth.php';
include 'lib/EpiTwitter.php';
include 'lib/secret.php';

        $twitterObj = new EpiTwitter($consumer_key, $consumer_secret);

        $oauth_token = $_GET['oauth_token'];


if($oauth_token == '')
{ 
    $url = $twitterObj->getAuthorizationUrl();
    echo "";
    echo "Sign In with Twitter";
    echo "";
} 
else
{

        $twitterObj->setToken($_GET['oauth_token']);
        $token = $twitterObj->getAccessToken();
        $twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);   

        $_SESSION['ot'] = $token->oauth_token;
        $_SESSION['ots'] = $token->oauth_token_secret;
        $twitterInfo= $twitterObj->get_accountVerify_credentials();
        $twitterInfo->response;

    $username = $twitterInfo->screen_name;
    $profilepic = $twitterInfo->profile_image_url;

    include 'update.php';
} 

if(isset($_POST['submit']))
{
    $msg = $_REQUEST['tweet'];

    $twitterObj->setToken($_SESSION['ot'], $_SESSION['ots']);
    $update_status = $twitterObj->post_statusesUpdate(array('status' => $msg));
    $temp = $update_status->response;


    header("Location: MessageStatus.html");
    exit();
}

?> 
  • 写回答

1条回答 默认 最新

  • dpnw86361 2010-12-23 18:31
    关注
    Share content on twitter";
    
    include 'lib/EpiCurl.php';
    include 'lib/EpiOAuth.php';
    include 'lib/EpiTwitter.php';
    include 'lib/secret.php';
    
            $twitterObj = new EpiTwitter($consumer_key, $consumer_secret);
    
            $oauth_token = empty($_SESSION['ot']) ?  $_GET['oauth_token']:$_SESSION['ot'];
    
    
    if($oauth_token == '')
    { 
        $url = $twitterObj->getAuthorizationUrl();
    
            echo "";
            echo "Sign In with Twitter";
            echo "";
    
    
    } 
    else
    {
            if(empty($_SESSION['ot']))
            {
                $twitterObj->setToken($_GET['oauth_token']);
                $token = $twitterObj->getAccessToken();
                $twitterObj->setToken($token->oauth_token, $token->oauth_token_secret);   
    
                $_SESSION['ot'] = $token->oauth_token;
                $_SESSION['ots'] = $token->oauth_token_secret;
            }
            else
            {
                $twitterObj->setToken($_SESSION['ot'], $_SESSION['ots']);   
            }
            $twitterInfo= $twitterObj->get_accountVerify_credentials();
            $twitterInfo->response;
    
        $username = $twitterInfo->screen_name;
        $profilepic = $twitterInfo->profile_image_url;
    
        include 'update.php';
    } 
    
    if(isset($_POST['submit']))
    {
        $msg = $_REQUEST['tweet'];
        try { 
        $twitterObj->setToken($_SESSION['ot'], $_SESSION['ots']);
        $update_status = $twitterObj->post_statusesUpdate(array('status' => $msg));
        $temp = $update_status->response;
    
    
    
    
         } 
        catch (Exception $e) 
        {
    
        } 
    }
    
    ?> 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集