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
775 stars 237 forks source link

Undefined property: stdClass::$oauth_token #227

Closed ekodikara closed 5 years ago

ekodikara commented 6 years ago
$message = base64_decode($request->t);
        $image = base64_decode($request->i);

        $replay = '';

        if(empty($message) || empty(image)){

        }else{
            define('CONSUMER_KEY', 'aAKDieO123'); // replace with your key
            define('CONSUMER_SECRET', 'VsI8D3oQKS123'); // your secret instead
            Codebird::setConsumerKey(CONSUMER_KEY, CONSUMER_SECRET);
            $cb = Codebird::getInstance();
            //dd($cb);
            /*$cb->setToken('2540113038-vvnZfBAc3CE3Yrr2t7DoaXAIAk4hhR8IrTV2kXk','oxnZh4Gm1L6wyM0SfPnv7rqRvWLmFcIMk3Hz8hkpZ4i08');
            $replay = $cb->statuses_update('status=Whohoo, I just Tweeted! from orivet #cc3');*/
            session_start();
            if (!isset($_SESSION['oauth_token'])) {
                //echo('tt');
                $replay = $cb->oauth_requestToken([
                    'oauth_callback' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']
                ]);
                $cb->setToken($replay->oauth_token, $replay->oauth_token_secret);
                $_SESSION['oauth_token'] = $replay->oauth_token;
                $_SESSION['oauth_token_secret'] = $replay->oauth_token_secret;
                $_SESSION['oauth_verify'] = true;
                $auth_url = $cb->oauth_authorize();
                header('Location: ' . $auth_url);
                die();

            } elseif (isset($_GET['oauth_verifier']) && isset($_SESSION['oauth_verify'])) {
                //echo ('xx');
                $cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
                unset($_SESSION['oauth_verify']);
                $replay = $cb->oauth_accessToken([
                    'oauth_verifier' => $_GET['oauth_verifier']
                ]);
                $_SESSION['oauth_token'] = $replay->oauth_token;
                $_SESSION['oauth_token_secret'] = $replay->oauth_token_secret;
                header('Location: ' . basename(__FILE__));
                die();
            }
            //echo ('kk');
            $cb->setToken($_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);

            $media_files = [
                $image
            ];

            $media_ids = [];

            foreach ($media_files as $file) {

                $replay = $cb->media_upload([
                    'media' => $file
                ]);
            }

            if (empty($replay->errors[0])) {
                $media_ids[] = $replay->media_id_string;
                $media_ids = implode(',', $media_ids);

                $replay = $cb->statuses_update([
                    'status' => str_replace('   ', '', strip_tags($message)),
                    'media_ids' => $media_ids
                ]);
                $cb->logout();
            } else {
                $cb->logout();
            }

        }

I used above code and getting the error "Undefined property: stdClass::$oauth_token"

Any suggestion ? Some time this not happen :(

emilorol commented 6 years ago

Register you app URL as a callback URL on your app.

'oauth_callback' => 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']

Note: just in case you might want to use HTTPS on the URL to save a redirect.

emilorol commented 6 years ago

Here are the steps:

https://github.com/jublonet/codebird-php/issues/49

mynetx commented 5 years ago

@elshan Did you try @emilorol’s steps?

mynetx commented 5 years ago

Closing since there were no further replies.