ogp icon indicating copy to clipboard operation
ogp copied to clipboard

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

Open akoskovacs opened this issue 3 years ago • 2 comments

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>'

akoskovacs avatar May 22 '21 22:05 akoskovacs

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

azeemh avatar Jun 05 '21 17:06 azeemh

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

azeemh avatar Jun 07 '21 19:06 azeemh