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

OGP::MalformedSourceError when trying to parse Twitter posts/users #11

Open
akoskovacs opened this issue May 22, 2021 · 2 comments
Open

Comments

@akoskovacs
Copy link

Hi! It seems OGP is unable to parse Twitter's OpenGraph properties.

I think the problem might be that the meta tag's attributes are in an unusual order. This code shows the problem:

require 'http'
require 'ogp'

class OGPTest
  attr_accessor :href

  def initialize(href: nil)
    @href = href
  end

  def analyze_opengraph
    return nil if @href.nil?

    begin
      connection = HTTP
        .follow(max_hops: 5)
        .timeout(30)
        .get(@href)

      if connection.status == 200
        return OGP::OpenGraph.new(connection.body.to_str)
      end
    rescue Exception => e
      puts "Error while trying to access '#{@href}'"
      raise
      return nil
    end
  end
end

c = OGPTest.new href: 'https://twitter.com/jack'
puts c.analyze_opengraph

Outputs:

Error while trying to access 'https://twitter.com/jack'
/home/akos/.rvm/gems/ruby-3.0.0/gems/ogp-0.5.0/lib/ogp/open_graph.rb:27:in `initialize': OGP::MalformedSourceError (OGP::MalformedSourceError)
	from a.rb:22:in `new'
	from a.rb:22:in `analyze_opengraph'
	from a.rb:33:in `<main>'
@azeemh
Copy link

azeemh commented Jun 5, 2021

I have this same problem. It also happens on soundcloud links.

@azeemh
Copy link

azeemh commented Jun 7, 2021

so i found that twitter doesn't actually implement OGP when discussing this at Open Graph Reader. Open Graph Reader also worked on soundcloud links. just an fyi for anyone else who runs into this. peace

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants