jdelamater99 / Twitter-RSS-Parser

Convert Twitter API v1.1 JSON to RSS
Other
70 stars 18 forks source link

Including full Tweet and pictures within RSS description #8

Open patrickbootscec opened 4 years ago

patrickbootscec commented 4 years ago

Hello, I've downloaded and used the Twitter to RSS Parser with great success, but I was wondering if certain functionality is possible. I've noticed after about 12 or 13 words the rest of a longer Tweet will get cut off and appended with an ellipsis.

Is there any way to include the full Tweet? Also, is it possible to embed Twitter images within the RSS description with a change to these files?

Thanks for making the script, @jdelamater99, @craywolf, and @kuc since it does work better than all the others I've tried.

ianchanning commented 4 years ago

As this project hasn't been updated for a while I'm not sure if you'll get a response. But it should be possible for you to debug this yourself.

Looking at https://github.com/jdelamater99/Twitter-RSS-Parser/blob/master/functions.php one thing you'll see at the end is that you can pass a 'test' parameter https://github.com/jdelamater99/Twitter-RSS-Parser/blob/c159d164a17b6da8e64617c11def953d4a474644/functions.php#L78:

if (isset( $_GET["test"] )){    
    print('id: ' . gettype($twitter_data[0]['id']). '<br>'. PHP_EOL);
    print('id_str: ' . gettype($twitter_data[0]['id_str']). PHP_EOL);

    if ($_GET["test"] == 'json')
        $test = $json;
    else
        $test = $twitter_data;

    printArray($test);

    printArray("url: + " . $url);
}

So for whatever URL you've created it for add &test=json onto the end and see what you get

For example: http://example.com/Twitter-RSS-Parser?q=kittens&test=json

That should show you what JSON you get back directly from the Twitter API. It maybe that they are the ones filtering the length. I don't see anything in the code that modifies the length of the text that comes back.

patrickbootscec commented 4 years ago

Looking at the JSON, after each tweet that exceeds the limit the condition "truncated" is true.

Searching the API documentation, https://developer.twitter.com/en/docs/twitter-api/v1/tweet-updates says that the condition "truncated" will be false when "extended" tweets are enabled.

Is there a way to change the conditions using the Twitter to RSS Parser? I am new to JSON and PHP and I'm wondering whether or not this is possible.

ianchanning commented 4 years ago

I've made some guesses how this should work by including 'tweet_mode' => 'extended' in the query that is sent to the Twitter API. Plus I now pull out the 'full_text' instead of the 'text' as they suggest in the doc https://developer.twitter.com/en/docs/twitter-api/v1/tweet-updates

Could you try testing this by downloading the code from my 'fixed' version: https://github.com/ianchanning/Twitter-RSS-Parser/tree/patch-1

patrickbootscec commented 4 years ago

This new version works like a charm! I can now see the full expressed tweets. Thank you so much for working that out.

I was looking at the JSON that I guess the Twitter API is providing us and I noticed that there's a condition for "expanded_url" and "url" if the Tweet has a link in it. The documentation explains these differences, https://developer.twitter.com/en/docs/tco and also explains the "t.co" formats.

For the Twitter to RSS Parser, the function "processString" appears to handle this sort of thing:

https://github.com/jdelamater99/Twitter-RSS-Parser/blob/c159d164a17b6da8e64617c11def953d4a474644/functions.php#L69

Is there a way to use the "expanded_url" condition for the text displayed?

ianchanning commented 4 years ago

Ok, great to hear that that works.

For your next question - I've raised that as a separate issue #10 and put a quick answer there.