Skip to content

Commit

Permalink
Wall.post
Browse files Browse the repository at this point in the history
  • Loading branch information
Vorkytaka committed Apr 18, 2017
1 parent 69c768e commit 0b1e771
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,37 @@ Set user status:
userID := 1
ok, err := vk.Status.Set("New status", userID)
```
Post photo on wall:
```go
// your id or
// id of group
id := 0

server, err := vk.Photos.GetWallUploadServer(id)
if err != nil {
log.Fatal(err)
}

// path to the image
path := "./example/x.png"
uploaded, err := vk.Upload.PhotoWall(server.Response.UploadURL, path)
if err != nil {
log.Fatal(err)
}

saved, err := vk.Photos.SaveWallPhoto(0, id, uploaded.Photo, uploaded.Hash, "", uploaded.Server, 0, 0)
if err != nil {
log.Fatal(err)
}

text := "Caption for the post"

// -id if you post to group wall
postID, err := vk.Wall.Post(id, false, true, false, false, false, text, saved.Response[0].ID, "", "", 0, 0, 0, 0, 0)
if err != nil {
log.Fatal(err)
}
```

### If you need to call method that not done yet:
```go
Expand Down Expand Up @@ -58,5 +89,7 @@ if err != nil {
* [Status](https://vk.com/dev/status)
* [Get](https://vk.com/dev/status.get)
* [Set](https://vk.com/dev/status.set)
* [Wall](https://vk.com/dev/wall)
* [Post](https://vk.com/dev/wall.post)
* Upload
* PhotoWall
2 changes: 2 additions & 0 deletions easyvk/vk.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type VK struct {
Photos Photos
Status Status
Upload Upload
Wall Wall
}

// WithToken helps to initialize your
Expand All @@ -33,6 +34,7 @@ func WithToken(token string) VK {
vk.Photos = Photos{&vk }
vk.Status = Status{&vk }
vk.Upload = Upload{}
vk.Wall = Wall{&vk }
return vk
}

Expand Down
7 changes: 7 additions & 0 deletions easyvk/wall-response.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package easyvk

type wallPost struct {
Response struct {
PostID int `json:"post_id"`
} `json:"response"`
}
71 changes: 71 additions & 0 deletions easyvk/wall.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package easyvk

import (
"fmt"
"encoding/json"
)

// A Wall describes a set of methods
// to work with wall.
type Wall struct {
vk *VK
}

// Post adds a new post on a user wall or community wall.
// Can also be used to publish suggested or scheduled posts.
// Returns id of post.
func (w *Wall) Post(ownerID int,
friendsOnly, fromGroup, signed, markAsAds, adsPromotedStealth bool,
message, attachments, services, guid string,
publishDate, placeID, postID uint,
lat, long float64) (int, error) {

params := map[string]string{
"owner_id": fmt.Sprint(ownerID),
"message": message,
"attachments": attachments,
"services": services,
"guid": guid,
"publish_date": fmt.Sprint(publishDate),
"place_id": fmt.Sprint(placeID),
"post_id": fmt.Sprint(postID),
"lat": fmt.Sprint(lat),
"long": fmt.Sprint(long),
}
if friendsOnly {
params["friends_only"] = "1"
} else {
params["friends_only"] = "0"
}
if fromGroup {
params["from_group"] = "1"
} else {
params["from_group"] = "0"
}
if signed {
params["signed"] = "1"
} else {
params["signed"] = "0"
}
if markAsAds {
params["mark_as_ads"] = "1"
} else {
params["mark_as_ads"] = "0"
}
if adsPromotedStealth {
params["ads_promoted_stealth"] = "1"
} else {
params["ads_promoted_stealth"] = "0"
}

resp, err := w.vk.Request("wall.post", params)
if err != nil {
return 0, nil
}
var info wallPost
err = json.Unmarshal(resp, &info)
if err != nil {
return 0, nil
}
return info.Response.PostID, nil
}

0 comments on commit 0b1e771

Please sign in to comment.