-
Notifications
You must be signed in to change notification settings - Fork 1
/
doc.go
95 lines (78 loc) · 3.12 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
Package instant enables creation and publishing of Facebook Instant Articles.
Full Facebook instant articles documentation can be found here
https://developers.facebook.com/docs/instant-articles
Struct instant.Article represents Facebook instant article as described on
https://developers.facebook.com/docs/instant-articles/guides/articlecreate
Use instant.Article and then use helper functions like SetTitle(), SetCoverImage() etc.
to easily create instant article without setting struct properties directly. Elemenets are
nested in inner struct, so using setter functions is much easier. Custom marshaler will generate
Facebook instant article valid html.
Example:
package main
import (
"encoding/xml"
"time"
"github.com/mileusna/facebook-instant-articles"
)
func main() {
a := instant.Article{}
// required
a.SetTitle("My article title")
a.SetCanonical("http://mysite/url-to-this-article")
a.SetPublish(time.Now())
a.SetContent("<p>My content</p><p>Other paragraph</p>")
// optional
a.SetSubtitle("My article subtitle")
a.SetKick("Exclusive")
a.SetFooter("", "(C)2016 MyComp")
a.AddAuthor("Michael", "http://facebook.com/mmichael", "Guest writter")
html, err := xml.Marshal(a)
if err != nil {
return
}
// html contains Facebook instant article html as []byte
}
Struct instant.Feed represents Facebook instant article RSS feed as described on
https://developers.facebook.com/docs/instant-articles/publishing/setup-rss-feed
Use instant.NewFeed() to create initial struct with all headers set up and
use helper functions like AddArticles to add instant.Article to feed. Custom
marshaler provides valid Facebook instant article RSS feed.
Example:
package main
import (
"encoding/xml"
"net/http"
"time"
"github.com/mileusna/facebook-instant-articles"
)
func main() {
http.HandleFunc("/instant-articles/", handleInstantArticles)
http.ListenAndServe(":8080", nil)
}
func handleInstantArticles(w http.ResponseWriter, r *http.Request) {
var f instant.Feed
// I don't believe Facebook cares about feed title, link and description, but you can set them
f.SetTitle("Title feed")
f.SetLink("http://www.mysite.com")
f.SetDescription("Feed description")
var a instant.Article
a.SetTitle("My article title")
a.SetCanonical("http://mysite/url-to-this-article")
a.SetPublish(time.Now())
a.SetContent("<p>Pragraph 1</p><p>paragraph 2</p>")
f.AddArticle(a) // add article, GUID will be hash of URL
a = instant.Article{}
a.SetTitle("My other title")
a.SetCanonical("http://mysite/url-to-this-article-number-two")
a.SetPublish(time.Now())
a.SetContent("<p>Pragraph 1</p><p>paragraph 2</p>")
f.AddArticleWithGUID(a, "12333") // add article and use for example mysql id as GUID
feed, err := xml.Marshal(f)
if err != nil {
return
}
w.Write(feed)
}
*/
package instant