Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
github.com/azr/golang-instagram
Implemented:
interface{}
data types! (1 exception, see Location.Id note below)Todo:
go get github.com/azr/golang-instagram
import (
"github.com/azr/golang-instagram"
)
unauthenticatedApi := &instagram.Api{
ClientId: "my-client-id",
}
authenticatedApi := &instagram.Api{
AccessToken: "my-access-token",
}
anotherAuthenticatedApi := instagram.New("", "my-access-token")
See the documentation, endpoint examples, and the iteration tests for a deeper dive than whats below.
import (
"fmt"
"github.com/azr/golang-instagram"
"net/url"
)
func DoSomeInstagramApiStuff(accessToken string) {
api := New("", accessToken)
if ok, err := api.VerifyCredentials(); !ok {
panic(err)
}
var myId string
// Get yourself!
if resp, err := api.GetSelf(); err != nil {
panic(err)
} else {
// A response has two fields: Meta which you shouldn't really care about
// And whatever your getting, in this case, a User
me := resp.User
fmt.Printf("My userid is %s and I have %d followers\n", me.Id, me.Counts.FollowedBy)
}
params := url.Values{}
params.Set("count", "1")
if resp, err := api.GetUserRecentMedia("self" /* this works :) */, params); err != nil {
panic(err)
} else {
if len(resp.Medias) == 0 { // [sic]
panic("I should have some sort of media posted on instagram!")
}
media := resp.Medias[0]
fmt.Println("My last media was a %s with %d comments and %d likes. (url: %s)\n", media.Type, media.Comments.Count, media.Like.Count, media.Link)
}
}
There's many more endpoints and a fancy iteration wrapper. Check it out in the code and documentation!
So pagination makes iterating through a list of users or media possible, but its not easy. So, because Go has nice iteration facilities (i.e. range
), this package includes two useful methods for iterating over paginating: api.IterateMedias
and api.IterateUsers
. You can see the tests and the docs for more info.
// First go and make the original request, passing in any additional parameters you need
res, err := api.GetUserRecentMedia("some-user", params)
if err != nil {
panic(err)
}
// If you plan to break early, create a done channel. Pass in nil if you plan to exhaust the pagination
done := make(chan bool)
defer close(done)
// Here we get back two channels. Don't worry about the error channel for now
medias, errs := api.IterateMedia(res, done)
for media := range medias {
processMedia(media)
if doneWithMedia(media) {
// This is how we signal to the iterator to quit early
done <- true
}
}
// If we exited early due to an error, we can check here
if err, ok := <- errs; ok && err != nil {
panic(err)
}
To run the tests, you'll need at least a ClientId
(which you can get from here), and preferably an authenticated users' AccessToken
, which you can get from making a request on the API Console
First, fill in config_test.go.example
and save it as config_test.go
. Then run go test
Api
. Also, there is a 5000 request per hour rate limit on any one ClientId or AccessToken, so it is advisable to use AccessTokens when available. This package will use it if it is given over a ClientId.interface{}
. But there is a facility to force it to a string, as follows:var loc Location
stringIdVersion := instagram.ParseLocationId(loc.Id)
If anyone can prove to me that they fixed this bug, just let me know and we can change it to a string (all other IDs are strings...)
created_time
fields come back as strings. So theres a handy type StringUnixTimeStringUnixTime
which has a nice method func (sut StringUnixTime) Time() (time.Time, error)
that you can use to cast it to a golang time.MIT-style. See LICENSE file.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.