Swiftpack.co - Package - satoshi-takano/OpenGraph
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.

A Swift wrapper for Open Graph protocol (OGP)

Build Status Carthage compatible Platform
OpenGraph is a Swift wrapper for OGP (Open Graph protocol). You can fetch OpenGraph and get access to the attributes using subscript and enum cases as follows.

OpenGraph.fetch(url: url) { result in
    switch result {
    case .success(let og):
        print(og[.title]) // => og:title of the web site
        print(og[.type])  // => og:type of the web site
        print(og[.image]) // => og:image of the web site
        print(og[.url])   // => og:url of the web site
    case .failure(let error):

All metadatas are defined here.
This library doesn't provide any platform specific views to display OGP data for high portability.

Furthermore, please copy the extension below to your own project if you want to use this library with the Rx interface.

extension Reactive where Base: OpenGraph {
    static func fetch(url: URL?) -> Observable<OpenGraph> {
        return Observable.create { observer in
            guard let url = url else {
                return Disposables.create()

            OpenGraph.fetch(url: url) { result in
                switch result {
                case .success(let og):
                case .failure(let error):

            return Disposables.create()


  • Xcode 11.x / Swift 5.x (If you use Xcode 10.x, you can use 1.1.0.)
  • iOS 8.0 or later
  • macOS 10.9 or later
  • tvOS 9.0 or later
  • watchOS 2.0 or later

If you use Swift 2.2 or 2.3, use older version of OpenGraph.



Insert pod 'OpenGraph' to your Podfile and run pod install.


Insert github "satoshi-takano/OpenGraph" to your Cartfile and run carthage update.

How to handle redirections

In most cases, the OpenGraph can handle server-side redirections automatically. But some web pages provoke redirections on their front-end JavaScript. You might be able to handle these kind of redirections by changing the User-Agent as follows.


This library is under the MIT License.


Stars: 89


1.2.3 - 2021-01-11T04:18:25

1.2.0 - 2019-08-19T01:37:05

  • Set language version Swift5.
  • You are able to get Result type in a completion handler.

1.0.5 - 2018-09-30T07:33:03

7.14.0 - 2018-09-29T06:18:30

Fix #29.

1.0.3 - 2017-09-18T02:23:52

Swift4 compatibility.

1.0.2 - 2017-08-12T03:47:39

Library update

- 2017-01-30T02:53:56

Fix #24.

- 2017-01-15T08:58:02


  • Parse OGP also when other attributes are included in the meta tag.

0.4.0 - 2017-01-05T03:51:01

Add customizable http header method.

0.3.1 - 2017-01-02T05:14:57


  • Detect og:xxx also when order of attributes are reversed.

0.3.0 - 2016-10-05T01:53:32

Swift Package Manager

0.2.0 - 2016-09-26T02:40:17

This release supports Swift 3.0 and Xcode8.0