jublo / codebird-php

Easy access to the Twitter REST API, Direct Messages API, Account Activity API, TON (Object Nest) API and Twitter Ads API — all from one PHP library.
https://www.jublo.net/projects/codebird/php
GNU General Public License v3.0
777 stars 235 forks source link

How long does session last???? Never able to get proper Oauth access token. #196

Closed Behinder closed 7 years ago

Behinder commented 7 years ago

I am struggling whole day with your library on my local server. In this code:

<?php
require __DIR__ . '/vendor/autoload.php';
require_once('vendor/jublonet/codebird-php/src/codebird.php');

\Codebird\Codebird::setConsumerKey('************','************************');
$cb=\Codebird\Codebird::getInstance();

session_start();

var_dump(isset($_SESSION['oauth_token']));

if (! isset($_SESSION['oauth_token'])) {
  //get the request token
  //
  echo "<h1>get token tokena</h1>";

  $reply = $cb->oauth_requestToken([
    'oauth_callback' => 'oob'
  ]);

// store the token
  $cb->setToken($reply->oauth_token, $reply->oauth_token_secret);
  $_SESSION['oauth_token'] = $reply->oauth_token;
  $_SESSION['oauth_token_secret'] = $reply->oauth_token_secret;
  $_SESSION['oauth_verify'] = true;

  // redirect to auth website
  $auth_url = $cb->oauth_authorize();
  header('Location: ' . $auth_url);
  echo $auth_url;
die();
}
$cb->logout(); //not sure where to put this line
?>

the part inside IF is never run. using var_dump shows me every time that session variable is set..wtf? I am never able to be redirected to auth webpage. I need tokens for my different account than the one I created an app. I tried running the page in different browsers, closing and opening windows but this is still the same. When I try to show this session variable I got "c6QOjwAAAAAAzMCgAAABWjywg3M" which obviously is NOT Oauth access token because it should start with my twitterID followed by "-". This is very frustrating (as well as whole Twitter API) 👎


Edit: Masked consumer key and secret.

mynetx commented 7 years ago

Sorry to hear you ran into so much trouble with your Codebird tries. Are you planning to use this for a desktop or for a web app?

Behinder commented 7 years ago

Well depend how you see "desktop" or "web". Let's say it's "web" because I need script who will be run on server side and posting tweets from time to time. To get script working I need Token for the twitter account that will post tweet. And I cannot get any :(

Behinder commented 7 years ago

I put scripts on external server instead of localhost. the same behaviour. Tomorrow I try different solutions, if there are any :/

mynetx commented 7 years ago

If it’s on the web, you need to provide a callback function to get the response token. The code will work, as it’s in use with many websites around.

If you just need a token to post to your own account, create an app at [apps.twitter.com]() and see the resulting access token and secret there. Does that work for you?

mynetx commented 7 years ago

Closing this due to no further reply received. If you see this and want to restart the conversation, feel free to comment here.