ラベル Instagram の投稿を表示しています。 すべての投稿を表示
ラベル Instagram の投稿を表示しています。 すべての投稿を表示

2016/05/17

[Instagram]一部のAPIがDeprecate

Facebookの投稿で一部のInstagramのAPIがDeprecateを知って、公式サイトで確認したら、確かに、そうなっていた。

Deprecate対象となっているのは、下記のAPI

/users/self/feed
/media/popular
/geographies/media/recent
/users/USER-ID/follows
/users/USER-ID/followed-by
確実にInstagramの視聴時間をあげるためのDeprecateですね。

「/media/popular」が取得できてしまうと3rdパーティ製のアプリで満足できてしまうので。

それを裏付けるかのように未だに3rdパーティアプリから写真の投稿ができないようになっている。

正式に広告で収益をあげていこうという戦略ですね。

Platform Changelog

2015/07/08

[instagram]APIのリクエスト時のsigを作成する方法

instagram apiのリクエストを実行する時に、Enforce signed requestsを選択しているとパラメーターにsigを追加しなければいけない。

そのアルゴリズムは下のような関数を一個用意すれば解決する。

import hmac
from hashlib import sha256

def generate_sig(endpoint, params, secret):
    sig = endpoint
    for key in sorted(params.keys()):
        sig += '|%s=%s' % (key, params[key])
    return hmac.new(secret, sig, sha256).hexdigest()

endpoint = '/media/657988443280050001_25025320'
params = {
    'access_token': 'fb2e77d.47a0479900504cb3ab4a1f626d174d2d',
    'count': 10,
}
secret = '6dc1787668c64c939929c17683d7cb74'

sig = generate_sig(endpoint, params, secret)
print sig


参考
Secure API Requests

2015/07/07

[instagram]APIのリクエスト回数を取得する方法

instagram apiのリクエストを実行する時に、残り回数を取得することができるみたいです。

Limits
で確認すると、HTTP Headerの

X-Ratelimit-Remainingで残り回数の確認ができる
X-Ratelimit-Limitで1時間あたりの最大コール回数を確認することができる。

2013/11/17

[iOS][Objective-c][Instagram]自分のアプリからInstagramを起動

昨日のエントリーでigoファイルまで保存できたので、いよいよ、今日は、Instagramを起動する方法について。

//igoファイルまでのパス
NSString *fileName;
interactionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileName]];
interactionController.UTI = @"com.instagram.exclusivegram";
//Instagramがオープンできない場合(selfは、UIVIewControllerを継承したクラス)
if(![interactionController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES]){

}
上のプログラムで実際に試したところうまくいきました。

これを実現するにあたり、1個だけ注意点。

下のプログラムだとクラッシュしましたー。
//igoファイルまでのパス
NSString *fileName;
UIDocumentInteractionController *interactionController = [UIDocumentInteractionController interactionControllerWithURL:[NSURL fileURLWithPath:fileName]];
interactionController.UTI = @"com.instagram.exclusivegram";
//Instagramがオープンできない場合(selfは、UIVIewControllerを継承したクラス)
if(![interactionController presentOpenInMenuFromRect:self.view.frame inView:self.view animated:YES]){

}
違いは、前者は、インスタンス変数として保持しているのに対し、後者は、その場で変数宣言しているところ。

結論から書くと、どうやら、インスタンス変数として保持していないといけないようです。

今後、実装する上で気をつけたいですね。

2013/11/16

[Instagram][iOS][Objective-C]igoファイルで画像を保存する

InstagramのAPIを読んでみると、どうやらigoファイルでjpegを保存すれば、Instagramに写真を共有することが可能なのだそうだ。

そこでさっそく画像ファイルをigoファイルとして保存する方法を考えてみた。

ちなみに、画像は、昨日紹介したtmpフォルダに保存することにする。

NSString *homeDirectory = NSHomeDirectory();
NSString *tmp = [homeDirectory stringByAppendingString:@"/tmp/"];

NSFileManager *manager = [NSFileManager defaultManager];
if ([manager fileExistsAtPath:tmp]) {
    if([manager isWritableFileAtPath:tmp]){
        UIImage *image;
        NSData* imageData = UIImageJPEGRepresentation(image,1.0);
        if([imageData writeToFile:[tmp stringByAppendingString:@"hoge.igo"] options:NSDataWritingAtomic error:nil]){

        }
    }
}
ファイル名は、違いますが、実際に試したら上の名前で保存できました。

Instagramでigoファイルでの保存方法が書かれていなかったので、こうしてまとめました。

2013/10/23

[Python][Google App Engine][Instagram]ユーザーの最新投稿を取得する

Instagramのユーザーがアップした写真や動画を取得するにはどうすればいいのだろうか?

下のように問い合わせたらいけた。

from google.appengine.api import urlfetch
#useridは、ユーザーID
useid = ""
#accesstokenは、認証で取得したtoken
accesstoken = ""
#countは、取得件数
count = 10
url = "https://api.instagram.com/v1/users/%s/media/recent/?access_token=%s&count=%s" % (userid,accesstoken,count)
result = urlfetch.fetch(url)
取得できたかどうかの判定は、前回書いたREST APIの構造についてにそって、Pythonコードをかけばおk

次回以降の問い合わせは、next_urlで取得しにいけばいいから便利です。

2013/10/17

[Instagram]REST APIの構造について

InstagramのREST APIを読みながら構造について調査

{
    "meta": {
        "code": 200
    },
    "data": {
        ...
    },
    "pagination": {
        "next_url": "...",
        "next_max_id": "13872296"
    }
}
まず、問い合わせを行って正常終了したかどうかを確認すには、metaキーのcodeを見ればおk。

200であることを確認した上で、dataキーの中をチェック。

paginationキーは、次の問い合わせができるかどうかの確認用に使うのだが、ない場合は、next_urlキーが存在しないので、注意が必要。

2013/08/07

[Instagram][Python][GoogleAppEngine]認証(ログイン)方法

Instagramの認証を読みながら実際に、ログイン方法について調べる。

Google App Engineを使った場合は、下のように実装できるようだ。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import webapp2
import json
import urllib
from google.appengine.api import urlfetch

class LoginInstagram(webapp2.RequestHandler):
 def get(self):
  self.redirect("https://api.instagram.com/oauth/authorize/?client_id=hoge&redirect_uri=http%3A%2F%2Ffoo.appspot.com%2Ftest%2Finsta%2Fredirect&response_type=code")
  

class RedirectFromInstagram(webapp2.RequestHandler):
 def get(self):
  self.response.headers['Content-Type'] = 'text/plain'
  code = self.request.get('code')

  url = "https://api.instagram.com/oauth/access_token"
  payload = urllib.urlencode({
   "client_id":"hoge",
   "client_secret":"hoge_secret",
   "grant_type":"authorization_code",
   "redirect_uri":"http://foo.appspot.com/test/insta/redirect",
   "code":str(code)
  })
  result = urlfetch.fetch(
   url=url,
   payload=payload,
   method=urlfetch.POST,
   headers={'Content-Type': 'application/x-www-form-urlencoded'}
  )
  if result.status_code == 200:
   #tokenの表示
   self.response.out.write(result.content)

app = webapp2.WSGIApplication([
 ('/test/insta', LoginInstagram),
 ('/test/insta/redirect', RedirectFromInstagram)
 ],debug=False
)
Oauth2だとこんなに簡単なものかとびっくりしてしまった。

ライブラリなどを使わずに実装できてしまうのである。

Oauth2は、どんどん普及してほしいなと思う昨今である。

2013/08/03

[Instagram]埋め込み機能を使う その2

前回は、単体の画像を取得する方法を書きましたが、今回は、コメント数とお気に入り数込みの整形された形での取得方法。

手順としては、取得したい画像のページまで「・・・」をクリックして「写真ページを表示」を選択する。

そこからさらに右下にある下のような画像をクリックすると「embed」という文字が表示されるのでそれを選択してでてきたコードを貼付けるだけ。
 photo Instagram06_zps4d1d8faf.png
なんと便利なのでしょうか!!

2013/08/02

[Instagram]埋め込み機能を使う

ちょっとInstagramのAPIを調べる必要があったので。
写真を直接取得した場合の方法は、

手順1:取得したい写真を選ぶ。
 photo Instagram01_zps013b5147.png
手順2:右下の「・・・」をクリックする
 photo Instagram02_zpsd126c1dd.png
手順3:上の画像で「写真ページを表示」を選択する
 photo Instagram03_zpsebba829a.png
手順4:上の画像のようにURLを確認する
 photo Instagram04_zpsea62d436.png
手順5:取得したURLにmediaを末尾につけると表示される

ちなみに、手順5で作ったURLをquerystringにして、下のようにアクセスするともう少し詳細な情報をゲットできる。
http://api.instagram.com/oembed?url=http://instagr.am/p/BUG/

これで埋め込みも怖くないっすねー。