Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding images and decription to tweets #1958

Closed
4 tasks
sagarpreet-chadha opened this issue Jan 11, 2018 · 42 comments
Closed
4 tasks

Adding images and decription to tweets #1958

sagarpreet-chadha opened this issue Jan 11, 2018 · 42 comments
Labels
enhancement explains that the issue is to improve upon one of our existing features first-timers-only They need to be well-formatted using the First-timers_Issue_Template. help wanted requires help by anyone willing to contribute Ruby

Comments

@sagarpreet-chadha
Copy link
Contributor

sagarpreet-chadha commented Jan 11, 2018

Hi, this is a first-timers-only issue. This means we've worked to make it more legible to folks who either haven't contributed to our codebase before, or even folks who haven't contributed to open source before.

If that's you, we're interested in helping you take the first step and can answer questions and help you out as you do. Note that we're especially interested in contributions from people from groups underrepresented in free and open source software!

If you have contributed before, consider leaving this one for someone new, and looking through our general help wanted issues. Thanks!

The Problem

Currently the tweets on PublicLab account have format :
screen shot 2018-01-11 at 6 25 28 pm

The problem is that the image is not shown on tweets and the description of the shared article is not shown .

Example : For research note , https://publiclab.org/notes/cutlan/01-09-2018/kilimanjaro-citizen-science-1 , the tweet is this .

Solution

We need to change the tweets to this format :

screen shot 2018-01-11 at 2 32 01 am

The tweets are generated from the recipe (Learn more about recipes from here) https://ifttt.com/applets/66362400d-rss-feed-to-post-a-tweet-with-image-and-url , which tweets whenever there is change in the RSS feed of Publiclab.com site https://publiclab.org/feed.rss .

We need to change the format of our RSS Builder , https://github.com/publiclab/plots2/blob/master/app/views/notes/rss.rss.builder to produce correct RSS Feeds .

The correct RSS feed has format similar to this , https://sagarpreet-chadha.github.io/feed.rss (this is a static feed only for testing).

Also , you can verify that the generated xml is of correct format from this site , https://validator.w3.org/feed/check.cgi .

1.) Basically to add images and description , we need to add this :
<![CDATA[ <img src="http://img02.mini.abroad.imgcdc.com/english/photos/fun/90/20170711/1017495_339353.jpg.680x425.jpg" alt="Smiley face"> ]]>
inside the <description> tag ,

xml.description auto_link(body, :sanitize => false)

2.)We need to remove the image tag inside <item> tag as <image> tag is not valid inside <item> tag .
Remove :

xml.image node.main_image.path(:default) if node.main_image

3.) Format of <author> tag is incorrect currently . The correct format is
<author> email-id (User-name) </author> .

xml.author node.author.name

Feel free to ask any doubt regarding the issue ! Thank you !

Steps to Fix

  • claim this issue with a comment here, below, and ask any clarifying questions you need
  • set up a repository locally following the README instructions, and make sure that all tests pass
  • try to fix the issue following the steps above, but even before you're done, you can:
    commit your changes and start a pull request (see contributing to Public Lab software) but mark it as "in progress" if you have questions or if you haven't finished
  • alert someone via the developers list (see below) to have your pull request merged. This may take a few extra steps depending on when you do it, but we'll help you out!

Please email the developers list (see https://publiclab.org/wiki/developers) or go to the chatroom if you have questions, and take a look at our first-timers landing page for more information!

@jywarren
Copy link
Member

This is a multi-step issue, but we're here to help! Please open a pull request with your initial code and feel free to ask for help - we can look it over and provide support.

@jywarren jywarren added enhancement explains that the issue is to improve upon one of our existing features help wanted requires help by anyone willing to contribute first-timers-only They need to be well-formatted using the First-timers_Issue_Template. Ruby labels Jan 11, 2018
@Mujadded
Copy link
Contributor

Can i claim it 😀 ?

@sagarpreet-chadha
Copy link
Contributor Author

Yes @Mujadded , go for it ! Feel free to ask any doubt regarding the issue .

Mujadded added a commit to Mujadded/plots2 that referenced this issue Jan 12, 2018
Mujadded added a commit to Mujadded/plots2 that referenced this issue Jan 13, 2018
jywarren pushed a commit that referenced this issue Jan 13, 2018
* adding tweet image and description (#1958)

* Author name changed in rss  ( fixes #1958 )
@sagarpreet-chadha
Copy link
Contributor Author

@jywarren , is it live ?

@jywarren
Copy link
Member

jywarren commented Jan 16, 2018 via email

@jywarren
Copy link
Member

jywarren commented Jan 16, 2018 via email

@jywarren
Copy link
Member

OK, it's live now!

@sagarpreet-chadha
Copy link
Contributor Author

https://publiclab.org/feed.rss seems to be not working . Looking into it .

@jywarren
Copy link
Member

server log:

Completed 500 Internal Server Error in 58ms (ActiveRecord: 10.5ms)

ActionView::Template::Error (undefined method `main_images' for #<Node:0x007f6eb3869240>
Did you mean?  main_image
               main_image_id):
     8:    @notes.each do |node|
     9: 
    10:      body = node.latest.render_body
    11:      body = "<p><![CDATA[ <img src='"+node.main_images.path(:default)+"' alt='"+node.main_image.title+"' > ]]></p> " + node.body if node.main_image
    12: 
    13:      xml.item do
    14:        xml.title       node.title
  app/views/notes/rss.rss.builder:11:in `block (3 levels) in _app_views_notes_rss_rss_builder__1936050186063288318_50813960'
  app/views/notes/rss.rss.builder:8:in `block (2 levels) in _app_views_notes_rss_rss_builder__1936050186063288318_50813960'
  app/views/notes/rss.rss.builder:3:in `block in _app_views_notes_rss_rss_builder__1936050186063288318_50813960'
  app/views/notes/rss.rss.builder:2:in `_app_views_notes_rss_rss_builder__1936050186063288318_50813960'
  app/controllers/notes_controller.rb:309:in `block (2 levels) in rss'
  app/controllers/notes_controller.rb:307:in `rss'

@jywarren
Copy link
Member

easy fix! and we should make a functional test for this :-)

@jywarren
Copy link
Member

Sorry, TravisCI is stalled for some hours ... waiting for that to come back before publishing!

@jywarren
Copy link
Member

The feed is now working: https://publiclab.org/feed/liked.rss

I just enabled the IFTTT recipe too. Fingers X!

@jywarren
Copy link
Member

And i posted a photo and liked it -- this should trigger the script! https://publiclab.org/notes/warren/01-18-2018/pre-order-the-community-written-pocket-guide-to-grassroots-mapping

@jywarren
Copy link
Member

It didn't work! Not sure why:

screenshot 2018-01-17 at 8 14 58 pm

@jywarren
Copy link
Member

Error:

EntryAuthor
warren
EntryContent
<p><![CDATA[ <img src='https://publiclab.org/system/images/photos/000/023/198/medium/26068242_2000536900161090_8104197322948214784_n.jpg' alt='' > ]]></p>This 3.5 x 5.5 inch illustrated booklet was printed at the AS220 community print shop by Jacque Bidon, and includes 64 pages of illustrated community-developed guidance and tips on balloon and kite mapping. It was [collaboratively written](<a href="https://publiclab.org/notes/warren/07-01-2017/collaboratively-write-the-new-pocket-guide-to-grassroots-mapping">https://publiclab.org/notes/warren/07-01-2017/collaboratively-write-the-new-pocket-guide-to-grassroots-mapping</a>) by dozens of Public Lab community members. Shown is the final mockup -- the final print will be in red ink. Available for pre-order now at $10 each! We expect to ship in February 2018: <a href="https://store.publiclab.org/products/pocket-guide-to-grassroots-mapping">https://store.publiclab.org/products/pocket-guide-to-grassroots-mapping</a> ![image description](<a href="https://publiclab.org/system/images/photos/000/023/199/large/download.jpg">https://publiclab.org/system/images/photos/000/023/199/large/download.jpg</a> "download.jpg")
EntryImageUrl
http://ifttt.com/images/no_image_card.png
EntryPublished
January 17, 2018 at 08:13PM
EntryTitle
Pre-order the community-written Pocket Guide to Grassroots Mapping
EntryUrl
https://publiclab.org/notes/warren/01-18-2018/pre-order-the-community-written-pocket-guide-to-grassroots-mapping
FeedTitle
Recent research notes on PublicLab.org
FeedUrl
https://publiclab.org/feed.rss

@jywarren jywarren reopened this Jan 18, 2018
@jywarren
Copy link
Member

I've turned the IFTTT script off for now! I wonder what happened?

@jywarren
Copy link
Member

Ooh, do we need an "enclosure" line? As per https://sagarpreet-chadha.github.io/feed.rss

<enclosure url="http://www.publiclab.org/system/images/photos/000/023/122/medium/PIC2.jpg" length="78645" type="image/jpeg" />

@jywarren
Copy link
Member

OK i got url= but not sure if we need type or length -- ? Can we test in your test setup, @sagarpreet-chadha ?

@jywarren jywarren mentioned this issue Jan 18, 2018
@jywarren
Copy link
Member

I'll be able to re-activate using this: https://ifttt.com/applets/70744657d-rss-feed-to-post-a-tweet-with-image-and-url

@sagarpreet-chadha
Copy link
Contributor Author

sagarpreet-chadha commented Jan 18, 2018

Oh so sorry , i had an exam in college , couldn't respond earlier .

@sagarpreet-chadha
Copy link
Contributor Author

The latest feed seems to work fine on my test setup :
https://github.com/sagarpreet-chadha/sagarpreet-chadha.github.io/blob/c3bcddea127ce0449d960da45c764d0b9b61c78d/feed.rss#L136

here is the image :
screen shot 2018-01-18 at 1 12 45 pm

@sagarpreet-chadha
Copy link
Contributor Author

The image is shown due to <![CDATA[ <img src=' and not <enclosure> tag !
We may remove that enclosure tag .

Tested this here : https://github.com/sagarpreet-chadha/sagarpreet-chadha.github.io/blob/d044a8c9a7124909dba78e0e2570b65a35f6d96a/feed.rss#L154

@sagarpreet-chadha
Copy link
Contributor Author

@jywarren , you were right it gets auto-truncated 😄 !!

@jywarren
Copy link
Member

Reopening -- one more thing, it tries to post an image even if there isn't an enclosure tag... Not sure how to stop this!

We may need to use a default image? But that's not a great solution.

@ebarry @steviepubliclab could we use someone's profile picture?

@jywarren jywarren reopened this Jan 18, 2018
@jywarren
Copy link
Member

Are you totally sure about enclosure? I think we have to do more testing. And to figure out how to not post an image if there isn't one.

@jywarren
Copy link
Member

This is a tough one! I disabled the ifttt script for now. Thanks for working on it!

@sagarpreet-chadha
Copy link
Contributor Author

I agree this is indeed a tricky one , learned a lot though . Thank you !

@jywarren
Copy link
Member

jywarren commented Jan 18, 2018 via email

@jywarren
Copy link
Member

Hmm, i can't seem to get this working effectively. Can you double check that enclosure is definitely not it?

@sagarpreet-chadha
Copy link
Contributor Author

Yes , i am pretty sure , also do try Mozilla Firefox to open your .rss file , it shows the rss feed with image and title .
Like this :
screen shot 2018-01-25 at 11 06 21 pm

@sagarpreet-chadha
Copy link
Contributor Author

Also , https://gist.github.com/jywarren/055bf4471dbdfff6a1ebd21bf15c3c8f file shows following errors according to https://validator.w3.org/feed/check.cgi .

screen shot 2018-01-25 at 11 08 35 pm

I think resolving these and removing enclosure tag may do the job .

@sagarpreet-chadha
Copy link
Contributor Author

Also @jywarren , i was thinking of not using the IFTTT recipes as these are not very flexible . I was thinking of using twitter gem , it has a very easy function client.update() to post on twitter . And we can post on twitter almost instantly (at the same time when the author post on publiclab.org site) and hence not waiting for IFTTT recipe to to run . However it might be a big project .
What do you think ? 😄

@jywarren
Copy link
Member

Hi, you know, I think that the twitter gem may be a way forward. But it does sound like a big project, and after all we have an API and RSS feeds specifically for integration -- i don't (architecturally) much like the idea of baking additional channels of publication into the core code.

I'd like to give this another attempt. Let's, for now, assume we can fall back to a profile picture if that exists, and the Public Lab logo (publiclab.org/logo) if /that/ doesn't exist.

So the remaining problem is how to get the image to appear in Twitter.

Actually while I see your test looks good, it only demonstrates that the image makes it into the RSS feed and is RSS compliant. We also need to know that the IFTTT feed is reading either the image from the item content, OR from the <enclosure> tag.

One clue, however, is that your original demonstration that got all the way to Twitter, included <enclosure> WITH a length attribute, which my test lacked. We could think about attaching file size but it's complicated.

Let's see if we can narrow down the problem using your original demo. Can you do your original test (https://sagarpreet-chadha.github.io/feed.rss) using <enclosure> without length, and if that breaks the system, we know that's the problem?

Thanks -- this is complex and I appreciate your time on it!

@jywarren
Copy link
Member

It could also be the type="image/jpeg" part of <enclosure> -- testing this idea here: https://publiclab.org/feed-tmp.rss + https://twitter.com/pl_testing

@sagarpreet-chadha
Copy link
Contributor Author

sagarpreet-chadha commented Jan 27, 2018

Hi , working on it .

Also @jywarren , i was thinking of an alternative and thought of this :

1.) Use this recipe to post on FB page :
screen shot 2018-01-28 at 2 29 54 am

2.)And then using this recipe , to post on Twitter (image is handled automatically and also description comes automatically) :
screen shot 2018-01-28 at 2 30 06 am

What do you think ?

@jywarren
Copy link
Member

hmm, it's not type -- i checked that using the feed-tmp.rss feed and pl_testing account. Testing length now.

@jywarren
Copy link
Member

Oh, cool -- maybe that can work! Does the Facebook/Twitter hybrid handle when only some posts have images?

@jywarren
Copy link
Member

yeah, nope -- length didn't help. I'm going to try both at once, but yeah... https://twitter.com/pl_testing

@jywarren
Copy link
Member

OK, for reference, none of the last ~8 items in this feed work: https://publiclab.org/feed-tmp.rss

@sagarpreet-chadha
Copy link
Contributor Author

Yes @jywarren , Unfortunately when the FB post does not has image then this recipe is working https://ifttt.com/applets/10891p-share-facebook-page-updates-on-twitter and when FB post has an image then this https://ifttt.com/applets/263954p-autopost-from-facebook-page-to-twitter is working fine .

Also in FB post , if we give only the link of node in the RSS , then the FB automatically fetches the image (if any) .

@sagarpreet-chadha
Copy link
Contributor Author

I think this combination of recipes may work ! What do you think ?

Also mine RSS Feed to Twitter is not working , so i am not able to test the RSS feed . Trying to resolve this ! Thanks 👍

SrinandanPai pushed a commit to SrinandanPai/plots2 that referenced this issue May 5, 2019
…b#1966)

* adding tweet image and description (publiclab#1958)

* Author name changed in rss  ( fixes publiclab#1958 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement explains that the issue is to improve upon one of our existing features first-timers-only They need to be well-formatted using the First-timers_Issue_Template. help wanted requires help by anyone willing to contribute Ruby
Projects
None yet
Development

No branches or pull requests

3 participants