Instaphpとcakephpを使ったInstagramアプリの作り方

irostagram プログラミング

irostagram

Popularは女性の写真ばかり、アクティブなユーザーも減ってそうなInstagram
とはいえ就活に使うような人もいるぐらいだからまだまだ使っている人もたくさんいるはず…

という感じでもうちょっと違う写真を見たくて以前作って放置してたIROSTAGRAMをすこし改修しました


元々cakephp2.0を試したくてcakephpを使っていたのでそこはそのまま生かしてInstaphpを使って簡単に作りなおしました

Instaphpを配置する

sesser / InstaphpからInstaphpを取得しvendorsに配置します

~~~
vendors/instaphp
~~~

githubに置かれているのでgit cloneすると色々便利です

Instaphpの設定をする

設定ファイルを作ります

~~~
cp vendors/Instaphp/config.sample.xml vendors/Instaphp/config.xml
~~~

Instagram Developer Documentationで取得したCLIENT IDとCLIENT SECRETとCALLBACK URLを書きます

~~~



https://api.instagram.com
v1
CLIENT ID
CLIENT SECRET
comments+likes+relationships
/oauth/authorize/?client_id={ClientId}&response_type=code& amp;redirect_uri={RedirectUri}
/oauth/access_token/


CALLBACK URL









~~~

Instaphpを呼び出す

Controllerに追記します

~~~
App::import(‘Vendor’, ‘Instaphp’);
class HomuhomuController extends AppController {
~~~

Instaphpを使う

例えばPopularを呼び出したい場合

コントローラー

~~~
function popular() {
$api = Instaphp\Instaphp::Instance();
$response = $api->Media->Popular();

if (empty($this->response->error)) {
$data = $response->data;
$this->set(compact(‘data’));
} else {
$error = $response->error;
$this->set(compact(‘error’));
}
}
~~~

ビュー

~~~

コメント

タイトルとURLをコピーしました