Skip to content

siyoon210/ogparser4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ogparser4j

  • This is OpenGraph parser for Java.

Installation

Maven Central : ogparser4j

  1. maven
<dependency>
  <groupId>com.github.siyoon210</groupId>
  <artifactId>ogparser4j</artifactId>
  <version>1.0.1</version>
</dependency>
  1. gradle
implementation 'com.github.siyoon210:ogparser4j:1.0.1'

Usage

How to Get OpenGraph object from your target url.

OgParser ogParser = new OgParser();
OpenGraph openGraph = ogParser.getOpenGraphOf("https://target.url");

How to Get OpenGraph Value

  • sample meta elements
<meta property="og:title" content="Open Graph protocol" />
  • usage
OpenGraph.Content title = openGraph.getContentOf("title");
String titleValue = title.getValue(); // "Open Graph protocol"

How to Get Extra Data

  • sample meta elements
<meta property="og:image" content="https://ogp.me/logo.png" />
<meta property="og:image:type" content="image/png" />
  • usage
OpenGraph.Content image = openGraph.getContentOf("image");
String imageType = image.getExtraDataValueOf("type"); // "image/png"

How to Get Array Values

  • sample meta elements(1)
<meta property="og:image" content="https://ogp.me/logo.png" />
<meta property="og:image" content="https://ogp.me/logo2.png" />
  • usage(1)
OpenGraph.Content imageIndex0 = openGraph.getContentOf("image", 0); // you can omit index 0.
OpenGraph.Content imageIndex1 = openGraph.getContentOf("image", 1);

String image0 = imageIndex0.getValue(); // "https://ogp.me/logo.png"
String image1 = imageIndex1.getValue(); // "https://ogp.me/logo2.png"

  • sample meta elements(2)
<meta property="og:image" content="https://ogp.me/logo.png" />
<meta property="og:image:width" content="300" />
<meta property="og:image" content="https://ogp.me/logo2.png" />
<meta property="og:image:width" content="200" />
  • usage(2)
OpenGraph.Content imageIndex0 = openGraph.getContentOf("image", 0); // you can omit index 0.
OpenGraph.Content imageIndex1 = openGraph.getContentOf("image", 1);

String image0Width = imageIndex0.getExtraDataValueOf("width"); // "300"
String image1Wdith = imageIndex1.getExtraDataValueOf("width); // "200"

OpenGraph Protocol Summary

OpenGraph Protocol Summary

Class Diagram

class-diagram

About

This is OpenGraph parser for Java.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages