ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - Medium/medium-sdk-go: A Golang SDK for Medium's OAuth2 API
A Golang SDK for Medium's OAuth2 API. Contribute to Medium/medium-sdk-go development by creating an account on GitHub.
Visit Site

GitHub - Medium/medium-sdk-go: A Golang SDK for Medium's OAuth2 API

GitHub - Medium/medium-sdk-go: A Golang SDK for Medium's OAuth2 API

Medium SDK for Go

This repository contains the open source SDK for integrating Medium's OAuth2 API into your Go app.

Install

go get github.com/Medium/medium-sdk-go

Usage

Create a client, then call commands on it.

package main

import (
	medium "github.com/medium/medium-sdk-go"
	"log"
)

func main() {
	// Go to https://medium.com/me/applications to get your applicationId and applicationSecret.
	m := medium.NewClient("YOUR_APPLICATION_ID", "YOUR_APPLICATION_SECRET")

	// Build the URL where you can send the user to obtain an authorization code.
	url := m.GetAuthorizationURL("secretstate", "https://yoursite.com/callback/medium",
        medium.ScopeBasicProfile, medium.ScopePublishPost)

	// (Send the user to the authorization URL to obtain an authorization code.)

	// Exchange the authorization code for an access token.
	at, err := m.ExchangeAuthorizationCode("YOUR_AUTHORIZATION_CODE", "https://yoursite.com/callback/medium")
	if err != nil {
		log.Fatal(err)
	}

	// The access token is automatically set on the client for you after
	// a successful exchange, but if you already have a token, you can set it
	// directly.
	m.AccessToken = at.AccessToken

	// If you have a self-issued access token, you can skip these steps and
	// create a new client directly:
	m2 := medium.NewClientWithAccessToken("SELF_ISSUED_ACCESS_TOKEN")

	// Get profile details of the user identified by the access token.
	// Empty string mean current user, otherwise you need to indicate
	// the user id (alphanumeric string with 65 chars)
	u, err := m2.GetUser("")
	if err != nil {
		log.Fatal(err)
	}

	// Create a draft post.
	p, err := m.CreatePost(medium.CreatePostOptions{
		UserID:        u.ID,
		Title:         "Title",
		Content:       "<h2>Title</h2><p>Content</p>",
		ContentFormat: medium.ContentFormatHTML,
		PublishStatus: medium.PublishStatusDraft,
	})
	if err != nil {
		log.Fatal(err)
	}

	// When your access token expires, use the refresh token to get a new one.
	nt, err := m.ExchangeRefreshToken(at.RefreshToken)
	if err != nil {
		log.Fatal(err)
	}

	// Confirm everything went ok. p.URL has the location of the created post.
	log.Println(url, at, u, p, nt)
}

Contributing

Questions, comments, bug reports, and pull requests are all welcomed. If you haven't contributed to a Medium project before please head over to the Open Source Project and fill out an OCLA (it should be pretty painless).

Authors

Jamie Talbot

Dan Pupius

Andrew Bonventre

License

Copyright 2015 A Medium Corporation

Licensed under Apache License Version 2.0. Details in the attached LICENSE file.

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory