GithubHelp home page GithubHelp logo

Comments (12)

ospfranco avatar ospfranco commented on June 1, 2024

can you provide the test case where it is failing? I got rid of most of the dependencies, so the javascript code is the same between the two platforms, it shouldn't be a problem.

from link-preview-js.

prakas25 avatar prakas25 commented on June 1, 2024

`if(!(url in globalImageURL)){
LinkPreview.getPreview(url)
.then(data => {
var images = data['images'];
var imageURL;

    if(images.length > 0){
      imageURL = images[0];
      globalImageURL[data.url] = imageURL;
      _this.props.shouldUpdateListView(true);
      return imageURL;
    }
    else {
      globalImageURL[data.url] = '';
    }
  })
  .catch(err => {
  });

  return '';
}
else {
  return globalImageURL[url];
}`

this is the code i am using for both ios and android..
(globalImageURL is a variable i am using to store already rendered image for the url if any)

from link-preview-js.

ospfranco avatar ospfranco commented on June 1, 2024

hmmm are you sure your code is doing what you expect, you seem to be mixing sync code (return globalImageURL[url];) with the promise call (globalImageURL[data.url] = imageURL;), it might be some rendering cycle not firing correctly.

In any case it would be helpful to have the exact URL where this is failing.

from link-preview-js.

prakas25 avatar prakas25 commented on June 1, 2024

No so the globalImageURL keeps the url image so that if i have to re render the same url i should not have to wait for the respone that is why i am pushing the image into globalImageURL[data.url]...
the issue in case of android is that i am getting following response

"{"url":"http://Facebook.com","title":"Facebook - लॉग इन किंवा साइन अप","description":"खाते तयार करा किंवा Facebook वर लॉग इन करा. मित्र, कुटूंब अाणि आपण ओळखत असलेल्‍या अन्‍य लोकांशी कनेक्‍ट व्‍हा. छायाचित्रे आणि व्हिडिओ सामायिक करा,...","mediaType":"website","images":[],"videos":[]}"

NOTE: actual response is in the JSON format i converted it string to send here i.e i am getting and working on the JSON response only

from link-preview-js.

prakas25 avatar prakas25 commented on June 1, 2024

as u can see in the response "images" is []

from link-preview-js.

ospfranco avatar ospfranco commented on June 1, 2024

ok, I will try to take a look asap

from link-preview-js.

prakas25 avatar prakas25 commented on June 1, 2024

ok

from link-preview-js.

ospfranco avatar ospfranco commented on June 1, 2024

I just tested it on both android and iOS:

    LinkPreview.getPreview('http://www.facebook.com')
      .then((res) => {console.warn(res); })
      .catch((err) => console.warn(err));

    LinkPreview.getPreview('https://www.youtube.com/watch?v=MejbOFk7H6c')
      .then((data) => console.warn(data))
      .catch((err) => console.warn(err));

console output:

Object {url: "https://www.youtube.com/watch?v=MejbOFk7H6c", title: "OK Go - Needing/Getting - Official Video - YouTube", description: "Buy the video on iTunes: https://itunes.apple.com/… the guitars at: http://www.gretschguitars.com...", mediaType: "video", images: Array(1)…}

Object {url: "http://www.facebook.com", title: "Facebook – Anmelden oder Registrieren", description: "Erstelle ein Konto oder melde dich bei Facebook an…rsonen, die du kennst. Teile Fotos und Videos,...", mediaType: "website", images: Array(0)…}

You are right, www.facebook.com is not returning any image in the array... but that is only facebook.com, I don't know what could be the problem, I took a look at the code again, image parsing is done via:

static _getImages(doc, rootUrl) {
    const images = [];
    const nodes = doc('meta[property=\'og:image\']');

    if (nodes.length > 0) {
      nodes.each((index, node) => { images.push(node.attribs.content); });
    }

    return images;
  }

If this is something you really need, feel free to submit a pull request, containing more tags to look for in the returned html, this seems to be a very specific case, that might have to do with the web page you are trying to crawl more than a problem with the library itself.

from link-preview-js.

ospfranco avatar ospfranco commented on June 1, 2024

Since I haven't heard back anything from @prakas25 I'm closing this, as said this seems to be an issue with the content served from facebook.com rather than a library issue.

Feel free to comment any other problem or send a pull request and it will be re-opened.

from link-preview-js.

prakas25 avatar prakas25 commented on June 1, 2024

i am really sorry for replying late @ospfranco . Actually in my case this response i.e images:[] is coming for other links too. i will look into it again later as i have some other priorities right now

from link-preview-js.

ospfranco avatar ospfranco commented on June 1, 2024

Just released version https://github.com/ospfranco/react-native-link-preview/releases/tag/V1.2.0 with a more thorough image crawling, I'm pretty sure at least some image should be returned now, can you please try it and let me know if it fixes the problems on android?

from link-preview-js.

prakas25 avatar prakas25 commented on June 1, 2024

hey hi thanks for upgrading the version but its still not working.
Note: This is working fine on IOS but still getting "images:[]" as result of LinkPreview.getPreview() which i already told you

I am sending you screenshots of the result
2017-09-08.zip

appreciate you efforts, thanks

from link-preview-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.