Skip to content

Commit 2875931

Browse files
committed
2 parents b285d92 + 0683d27 commit 2875931

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# OpenGraphParser
2+
[![](https://jitpack.io/v/Priyansh-Kedia/OpenGraphParser.svg)](https://jitpack.io/#Priyansh-Kedia/OpenGraphParser)
3+
4+
5+
A small and easy to use library which provides the convenience of using Open Graph Protocol in Android very easily.
6+
Create previews for links to share in Android very easily.
7+
8+
### Star this repo to show your support [stargazers](https://github.com/Priyansh-Kedia/OpenGraphParser/stargazers) for this repository. :star2:
9+
10+
Add this in your root build.gradle at the end of repositories:
11+
12+
allprojects {
13+
repositories {
14+
...
15+
maven { url 'https://jitpack.io' }
16+
}
17+
}
18+
19+
Add the dependency
20+
21+
dependencies {
22+
implementation 'com.github.Priyansh-Kedia:OpenGraphParser:<latest_version>'
23+
}
24+
25+
26+
27+
28+
29+
https://user-images.githubusercontent.com/52661249/127740097-51535912-6623-48ac-8a3f-7709ac9b968e.mp4
30+
31+
32+
33+
34+
# Implementation
35+
36+
private val openGraphParser = OpenGraphParser(this)
37+
38+
openGraphParser.parse(linkUrl) // To parse the link provided
39+
40+
The class required you to implement two callback functions, `onError(error: String)` and `onPostResponse(openGraphResult: OpenGraphResult)`. The former is invoked in case of error (incorrect url), and the latter is invoked on successful response.
41+
42+
The data class ***OpenGraphResult*** contains:
43+
44+
45+
- title -> The title of the page the link points to
46+
- description -> The description metadata of the page
47+
- url -> The url of the page
48+
- image -> The image metadata for the page
49+
- siteName -> The name of the website (BASE URL).
50+
- type -> The type of the object e.g., "video.movie".
51+
52+
Inside `onPostResponse(openGraphResult: OpenGraphResult)` you can use the data to show on your UI like this.
53+
54+
override fun onPostResponse(openGraphResult: OpenGraphResult) {
55+
linkPreviewLayout.apply {
56+
runOnUiThread {
57+
Glide.with(this@ChannelActivity).load(openGraphResult.image).into(linkImage)
58+
linkTitle.text = openGraphResult.title
59+
linkDescription.text = openGraphResult.description
60+
website.text = openGraphResult.siteName
61+
}
62+
}}
63+
*Make sure that you run UI related stuff on the **UI Thread***.
64+
65+
# Contributions
66+
- Fork the repo
67+
- Create a new branch and make changes
68+
- Push the code to the branch and make a PR! :+1:
69+
70+
# License
71+
Copyright 2021 Priyansh Kedia
72+
73+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
74+
75+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
76+
77+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
78+
79+
80+
### Found this library useful? :heart:
81+
82+
Support it by joining [stargazers](https://github.com/Priyansh-Kedia/OpenGraphParser/stargazers) for this repository. :star2:

0 commit comments

Comments
 (0)