See the reasons here: #8
NOTE: The old Instagram API is now deprecated; this package will now focus on the Instagram Graph API.
Dart Instagram client library. This library includes support for authentication, as well as all of the Instagram API v1 endpoints.
The API is entirely documented, for convenience. 👍
Users of
Angel
can use
package:angel_auth_instagram
to authenticate users with Instagram.
Coming soon: Subscriptions
If you already have an access token, you can authenticate a client.
Note: The user
property of the InstagramClient
will be null
.
var client = InstagramApiAuth.authorizeViaAccessToken('<access-token>');
var me = await client.users.self.get();
To perform authentication, use the InstagramApiAuth
class. All API scopes are
included as InstagramApiScope
constants for convenience.
var auth = new InstagramApiAuth('<client-id>', '<client-secret>',
redirectUri: Uri.parse('<redirect-uri>'),
scopes: [
InstagramApiScope.basic,
InstagramApiScope.publicContent,
// ...
]
);
Applications with no server-side component can implement implicit auth.
To get a redirect URI:
var redirectUri = auth.getImplicitRedirectUri();
window.location.href = redirectUri.toString();
This library also supports traditional OAuth2 authentication.
To obtain a redirect URI:
var redirectUri = auth.getRedirectUri();
var redirectUri = auth.getRedirectUri(state: 'foo.bar=baz');
res.redirect(redirectUri.toString());
After you have obtained an authorization code, you can exchange it for an access token,
and receive an InstagramClient
.
This example is an Angel handler:
app.get('/auth/instagram/callback', (RequestContext req, InstagramApiAuth instaAuth) async {
var client = await instaAuth.handleAuthorizationCode(req.query['code'], new http.Client());
var me = await client.users.self.get();
// Do something with the authenticated user...
});
You can also manage subscriptions:
main() {
var subscriptions = instaAuth.createSubscriptionManager(new http.Client());
}
The InstagramClient
contains several getters that correspond to endpoints. Each is an abstraction over
a specific Instagram API.
Here is an example with the relationships
API:
Future<bool> userFollowsMe(String userId, InstagramClient instagram) async {
var relationship = await instagram.relationships.toUser(userId).get();
return relationship.incomingStatus == IncomingStatus.followedBy;
}
This API includes several classes containing helpful constants:
InstagramApiScope
IncomingStatus
OutgoingStatus
RelationshipAction
MediaType
SubscriptionObject
SubscriptionAspect