Beispiel #1
0
func main() {
	flag.Parse()

	// Set our OAuth2 configuration up
	var (
		configSource = box.NewConfigSource(
			&oauth2.Config{
				ClientID:     *clientId,
				ClientSecret: *clientSecret,
				Scopes:       nil,
				Endpoint: oauth2.Endpoint{
					AuthURL:  "https://app.box.com/api/oauth2/authorize",
					TokenURL: "https://app.box.com/api/oauth2/token",
				},
				RedirectURL: "http://localhost:8080/handle",
			},
		)
		tok = &oauth2.Token{
			TokenType:    "Bearer",
			AccessToken:  *accessToken,
			RefreshToken: *refreshToken,
		}
		c = configSource.NewClient(tok)
	)

	resp, folder, err := c.FolderService().GetTrashedFolder("2303056557")
	fmt.Println("resp: ", resp)
	fmt.Println("err: ", err)
	pretty.Print(folder)

	// Print out the new tokens for next time
	fmt.Printf("%#v\n", tok)
}
Beispiel #2
0
Datei: main.go Projekt: wyc/box
func main() {
	flag.Parse()

	if len(*clientId) == 0 || len(*clientSecret) == 0 ||
		len(*accessToken) == 0 || len(*refreshToken) == 0 ||
		len(*fileId) == 0 {
		fmt.Println("unfortunately all flags must be provided")
		return
	}

	// Set our OAuth2 configuration up
	var (
		configSource = box.NewConfigSource(
			&oauth2.Config{
				ClientID:     *clientId,
				ClientSecret: *clientSecret,
				Scopes:       nil,
				Endpoint: oauth2.Endpoint{
					AuthURL:  "https://app.box.com/api/oauth2/authorize",
					TokenURL: "https://app.box.com/api/oauth2/token",
				},
				RedirectURL: "http://localhost:8080/handle",
			},
		)
		tok = &oauth2.Token{
			TokenType:    "Bearer",
			AccessToken:  *accessToken,
			RefreshToken: *refreshToken,
		}
		c = configSource.NewClient(tok)
	)

	resp, err := c.FileService().DownloadFile(*fileId)
	pretty.Print(resp)
	fmt.Println("err: ", err)

	// Read the content into bs
	var bs []byte
	defer resp.Body.Close()
	bs, err = ioutil.ReadAll(resp.Body)
	fmt.Println("ioutil.ReadAll err: ", err)
	fmt.Printf("read %d bytes", len(bs))

	// Print out the new tokens for next time
	fmt.Printf("%#v\n", tok)
}
Beispiel #3
0
func main() {
	flag.Parse()

	if len(*clientId) == 0 || len(*clientSecret) == 0 ||
		len(*accessToken) == 0 || len(*refreshToken) == 0 ||
		len(*folderID) == 0 {
		fmt.Println("unfortunately all flags must be provided")
		return
	}

	// Set our OAuth2 configuration up
	var (
		configSource = box.NewConfigSource(
			&oauth2.Config{
				ClientID:     *clientId,
				ClientSecret: *clientSecret,
				Scopes:       nil,
				Endpoint: oauth2.Endpoint{
					AuthURL:  "https://app.box.com/api/oauth2/authorize",
					TokenURL: "https://app.box.com/api/oauth2/token",
				},
				RedirectURL: "http://localhost:8080/handle",
			},
		)
		tok = &oauth2.Token{
			TokenType:    "Bearer",
			AccessToken:  *accessToken,
			RefreshToken: *refreshToken,
		}
		c = configSource.NewClient(tok)
	)

	resp, user, err := c.FolderService().Update(
		&box.Folder{
			ID:   *folderID,
			Name: "test-updated",
		},
	)
	fmt.Println("resp: ", resp)
	fmt.Println("err: ", err)
	pretty.Print(user)

	// Print out the new tokens for next time
	fmt.Printf("\n%#v\n", tok)
}
Beispiel #4
0
func main() {
	flag.Parse()

	if len(*clientId) == 0 || len(*clientSecret) == 0 ||
		len(*accessToken) == 0 || len(*refreshToken) == 0 {
		fmt.Println("unfortunately all flags must be provided")
		return
	}

	// Set our OAuth2 configuration up
	var (
		configSource = box.NewConfigSource(
			&oauth2.Config{
				ClientID:     *clientId,
				ClientSecret: *clientSecret,
				Scopes:       nil,
				Endpoint: oauth2.Endpoint{
					AuthURL:  "https://app.box.com/api/oauth2/authorize",
					TokenURL: "https://app.box.com/api/oauth2/token",
				},
				RedirectURL: "http://localhost:8080/handle",
			},
		)
		tok = &oauth2.Token{
			TokenType:    "Bearer",
			AccessToken:  *accessToken,
			RefreshToken: *refreshToken,
		}
		c = configSource.NewClient(tok)
	)

	resp, longPollInfo, err := c.EventService().LongPollURL()
	fmt.Println("resp: ", resp)
	fmt.Println("err: ", err)
	pretty.Print(longPollInfo)

	// Print out the new tokens for next time
	fmt.Printf("\n%#v\n", tok)

	connInfo := longPollInfo.Entries[0]
	resp, event, err := c.EventService().ListenForEvent(connInfo, "")
	fmt.Println("resp: ", resp)
	fmt.Println("err: ", err)
	pretty.Println(event)
}
Beispiel #5
0
func main() {
	flag.Parse()

	if len(*clientId) == 0 || len(*clientSecret) == 0 ||
		len(*accessToken) == 0 || len(*refreshToken) == 0 {
		fmt.Println("unfortunately all flags must be provided")
		return
	}

	// Set our OAuth2 configuration up
	var (
		configSource = box.NewConfigSource(
			&oauth2.Config{
				ClientID:     *clientId,
				ClientSecret: *clientSecret,
				Scopes:       nil,
				Endpoint: oauth2.Endpoint{
					AuthURL:  "https://app.box.com/api/oauth2/authorize",
					TokenURL: "https://app.box.com/api/oauth2/token",
				},
				RedirectURL: "http://localhost:8080/handle",
			},
		)
		tok = &oauth2.Token{
			TokenType:    "Bearer",
			AccessToken:  *accessToken,
			RefreshToken: *refreshToken,
		}
		c = configSource.NewClient(tok)
	)

	resp, eventCollection, err := c.EventService().Events(box.EventQueryOptions{
		StreamPosition: *streamPosition,
		StreamType:     *streamType,
		Limit:          *limit,
	})
	fmt.Println("resp: ", resp)
	fmt.Println("err: ", err)
	pretty.Print(eventCollection)
	fmt.Println("\n# events: ", len(eventCollection.Entries))

	// Print out the new tokens for next time
	fmt.Printf("\n%#v\n", tok)
}
Beispiel #6
0
func main() {
	flag.Parse()

	if len(*clientId) == 0 || len(*clientSecret) == 0 ||
		len(*accessToken) == 0 || len(*refreshToken) == 0 ||
		len(*fileId) == 0 {
		fmt.Println("unfortunately all flags must be provided")
		return
	}

	// Set our OAuth2 configuration up
	var (
		configSource = box.NewConfigSource(
			&oauth2.Config{
				ClientID:     *clientId,
				ClientSecret: *clientSecret,
				Scopes:       nil,
				Endpoint: oauth2.Endpoint{
					AuthURL:  "https://app.box.com/api/oauth2/authorize",
					TokenURL: "https://app.box.com/api/oauth2/token",
				},
				RedirectURL: "http://localhost:8080/handle",
			},
		)
		tok = &oauth2.Token{
			TokenType:    "Bearer",
			AccessToken:  *accessToken,
			RefreshToken: *refreshToken,
		}
		c = configSource.NewClient(tok)
	)

	resp, err := c.FileService().DownloadFile(*fileId)
	pretty.Print(resp)
	fmt.Println("err: ", err)
	// TODO(ttacon): actually download the file here for the example
	// to be more complete

	// Print out the new tokens for next time
	fmt.Printf("%#v\n", tok)
}
Beispiel #7
0
func main() {
	flag.Parse()

	if len(*clientId) == 0 || len(*clientSecret) == 0 ||
		len(*accessToken) == 0 || len(*refreshToken) == 0 ||
		len(*fileId) == 0 {
		fmt.Println("unfortunately all flags must be provided")
		return
	}

	// Set our OAuth2 configuration up
	var (
		configSource = box.NewConfigSource(
			&oauth2.Config{
				ClientID:     *clientId,
				ClientSecret: *clientSecret,
				Scopes:       nil,
				Endpoint: oauth2.Endpoint{
					AuthURL:  "https://app.box.com/api/oauth2/authorize",
					TokenURL: "https://app.box.com/api/oauth2/token",
				},
				RedirectURL: "http://localhost:8080/handle",
			},
		)
		tok = &oauth2.Token{
			TokenType:    "Bearer",
			AccessToken:  *accessToken,
			RefreshToken: *refreshToken,
		}
		c = configSource.NewClient(tok)
	)

	resp, file, err := c.FileService().CreateSharedLinkForFile(*fileId, "open", "", true, true)
	fmt.Println("resp: ", resp)
	fmt.Println("err: ", err)
	pretty.Print(file)

	// Print out the new tokens for next time
	fmt.Printf("%#v\n", tok)
}