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
776 stars 234 forks source link

Problem posting a tweet to 2 pages/accounts #218

Closed steven-cotterill closed 5 years ago

steven-cotterill commented 6 years ago

Hi, i've got the library working perfect posting to individual accounts. Is it possible to post to two seperate pages? There are different consumer keys and tokens. Any help here would be greatly appreciated.

` \Codebird\Codebird::setConsumerKey ($public_consumer_key, $public_consumer_secret); $cb = \Codebird\Codebird::getInstance(); $cb->setToken ($public_access_token, $public_access_token_secret);

            // File upload
            foreach ($media_files as $file) {
                $reply = $cb->media_upload(array(
                    'media' => $file
                ));
                $media_ids[] = $reply->media_id_string;
            }

            // Convert ID to string list
            $media_ids = implode(',', $media_ids);

            // Send Tweet and get response
            $reply = $cb->statuses_update(array(
                'status'    => $status,
                'media_ids' => $media_ids
            ));

            $cb->logout();

            \Codebird\Codebird::setConsumerKey ($trade_consumer_key, $trade_consumer_secret);
            $cb->setToken ($trade_access_token, $trade_access_token_secret);

            // File upload
            foreach ($media_files as $file) {
                $reply = $cb->media_upload(array(
                    'media' => $file
                ));
                $media_ids[] = $reply->media_id_string;
            }

            // Convert ID to string list
            $media_ids = implode(',', $media_ids);

            // Send Tweet and get response
            $reply = $cb->statuses_update(array(
                'status'    => $status,
                'media_ids' => $media_ids
            ));

`

steven-cotterill commented 6 years ago

Also, there is a problem when passing single or double quotes through to $status. They appear as encoded characters on the actual tweet.

I've tried many functions to fix this; htmlspecialchars, htmlentities, addslashes etc. Any help here would be great.

mynetx commented 6 years ago

@steven-cotterill Can you send me a sample code with status text containing a quote or double quote, along with the generated Tweet URL?

mynetx commented 6 years ago

Also, to use Codebird concurrently on 2 accounts, you would have to set the consumer keys for every access. Will that work?

steven-cotterill commented 6 years ago

Hi, thanks for getting back. Code is unchanged from the original post.

You can see a number of tests on my test Twitter account (https://twitter.com/steventraffick). The text being sent is usually just an image (which is fine), and text of "Test" 'twitter' (to test the quotations) and a link to the article.

Code for posting to both accounts can be seen below, but won't post to the second account.

           if ($page === 'both') { // Tweet to both accounts. Not working ATM.
                \Codebird\Codebird::setConsumerKey ($public_consumer_key, $public_consumer_secret);
                $cb = \Codebird\Codebird::getInstance();
                $cb->setToken ($public_access_token, $public_access_token_secret);

                // File upload
                foreach ($media_files as $file) {
                    $reply = $cb->media_upload(array (
                        'media' => $file
                    ));
                    $media_ids[] = $reply->media_id_string;
                }

                // Convert ID to string list
                $media_ids = implode(',', $media_ids);

                // Send Tweet and get response
                $reply = $cb->statuses_update(array (
                    'status'    => $status,
                    'media_ids' => $media_ids
                ));

                $cb->logout();

                \Codebird\Codebird::setConsumerKey ($trade_consumer_key, $trade_consumer_secret);
                $cb->setToken ($trade_access_token, $trade_access_token_secret);

                // File upload
                foreach ($media_files as $file) {
                    $reply = $cb->media_upload(array (
                        'media' => $file
                    ));
                    $media_ids[] = $reply->media_id_string;
                }

                // Convert ID to string list
                $media_ids = implode(',', $media_ids);

                // Send Tweet and get response
                $reply = $cb->statuses_update(array (
                    'status'    => $status,
                    'media_ids' => $media_ids
                ));

            }

I've also tried following the steps in "…use multiple Codebird instances?" with no luck.

Thanks!

stevie-c91 commented 6 years ago

Hi there, any update with this? The main issue for me is the quotations being show as &#8217 etc. Thank you.

mynetx commented 5 years ago

@stevie-c91 Can you give an example string for $status that results in wrong entities being Tweeted?

stevie-c91 commented 5 years ago

Hi, I got this sorted. The user was copying strangely formatted text straight from a PDF. Thank you.

mynetx commented 5 years ago

@stevie-c91 So the entities were in the PDF data already?

stevie-c91 commented 5 years ago

It's been a while now but IIRC the quotation marks were formatted strangely in the PDFs. When copied over, Twitter didn't have the font required to display them, so I don't think it's an issue with the library. Running a search and replace on the copied text, and changing them to proper quotation marks fixed the problem.