Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json: cannot unmarshal array into Go value of type medium.Publications #19

Open
deepakjois opened this issue Feb 7, 2018 · 1 comment

Comments

@deepakjois
Copy link

Executing the code below (access code deleted),

package main

import (
	"fmt"
	"log"

	medium "github.com/medium/medium-sdk-go"
)

func main() {
	m2 := medium.NewClientWithAccessToken("")

	user, err := m2.GetUser("")
	fmt.Printf("User is %q\n", user)
	pubs, err := m2.GetUserPublications(user.ID)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Printf("No. of publications: %d\n", len(pubs.Data))
}

leads to:

User is &{"1278b5260445c10f4e13b9f37f4f60e9e59376cbd8e5230bf1efd5f700160f860" "debugjois" "ದೀಪಕ್/दीपक/دیپک/Deepak" "https://medium.com/@debugjois" "https://cdn-images-1.medium.com/fit/c/400/400/1*VY6glnPvt0Zbgi-uplEV0g.jpeg"}
2018/02/07 16:25:19 json: cannot unmarshal array into Go value of type medium.Publications
exit status 1

@bobby-pratama
Copy link

bobby-pratama commented Dec 26, 2018

I had the same problem with this. The solution is make struct array of Publication and unmarshall result data to that struct

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants