2010-12-23 13 views
1

Ich habe eine Twitter-App erstellt, mit der ich Tweets posten kann. Das Problem, das ich nicht lösen kann, ist jedes Mal, wenn ich den Zugriff auf meine Anwendung erlauben muss.PHP OAuth Twitter

Also sagen wir mal, ich muss drei Nachrichten twittern, also muss ich alle drei mal Zugriff auf meine App erlauben.

Ich brauche nur, sobald Benutzer Zugriff auf meine App erlaubt hat, das nächste Mal sollte er nur aufgefordert werden, Zugang zu ermöglichen ist, dass, wenn er/sie neu anmeldet.

Hier ist mein Code, den ich

 
    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(); 
} 

?> 

Antwort

0
 
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) 
    { 

    } 
} 

?> 
bin mit