oh/instagram-bundle-2

使用 sesser (Randy) 的 Instaphp 作为 Symfony2 服务。适配使用 Instaphp v2 作为依赖。

安装: 87

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 1

分支: 7

类型:symfony-bundle

dev-master 2014-12-09 16:17 UTC

This package is not auto-updated.

Last update: 2024-09-24 16:40:29 UTC


README

使用 Instaphp(作者:sesser)作为 Symfony2 服务。适配使用 Instaphp v2 作为依赖。

安装

通过向 composer.json 中添加来按常规安装此包

"oh/instagram-bundle": "dev-master"

安装上述模块后,您需要更新您的 composer

run the command “php composer.phar update”

app/AppKernel.php 中注册该包

// app/AppKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Oh\InstagramBundle\OhInstagramBundle(),
    );
}

将以下行添加到 app/config/config.yml

imports:
	- { resource: @OhInstagramBundle/Resources/config/services.yml }

将以下配置添加到您的 parameters.yml

instagram_api_client_id: YOUR_API_ID
instagram_api_client_secret: YOUR_API_SECRET
instagram_timeout: 30
instagram_connect_timeout: 8

如果您对提供的路由满意,请将以下内容添加到 app/config/routing.yml

OhInstagramBundle:
    resource: "@OhInstagramBundle/Resources/config/routing.yml"
    prefix:   /

用法(控制器)

//finding a user
$query = "snoopdogg";

$api = $this->get('instaphp');
	
$response = $api->Users->Find($query);

$userInfo = $response->data[0];

// NB: pagination no longer compatible

您还可以测试用户是否已登录。

//is a user logged in?
$loggedIn = $this->get('instaphp_token_handler')->isLoggedIn();

用法(Twig)

视图中包含登录按钮。只需在您的 Twig 模板中实现此行

{{ render(controller('OhInstagramBundle:Instagram:instagramLoginStatus')) }}

您应该设置您的 Instagram API 账户以回调到 "OhInstagramBundle_callback" 路由,您可以自行设置,或使用提供的路由 - "/instaphp/callback"。

Instagram 认证令牌

包含 2 个 TokenHandlers。

  1. CookieToken - Instagram 认证代码存储在 cookie 中

    services:
        instaphp_token_handler:
            class:            Oh\InstagramBundle\TokenHandler\CookieToken
    
  2. UserToken - Instagram 认证代码存储在 User 实体中。您的 User 必须实现 setInstagramAuthCode() 和 getInstagramAuthCode() 方法。当 Instagram 的登录调用返回时,代码被设置,用户在 Handler 中持久化并刷新。

    services:
        instaphp_token_handler:
            class:            Oh\InstagramBundle\TokenHandler\UserToken
            arguments:        [@security.context, @doctrine.orm.default_entity_manager]
    
  3. Both - 如果无法从上下文中检索用户,则会将认证代码存储在 cookie 中。

    services:
        instaphp_user_token_handler:
            class:            Oh\InstagramBundle\TokenHandler\UserToken
            arguments:        [@security.context, @doctrine.orm.default_entity_manager]
        instaphp_cookie_token_handler:
            class:            Oh\InstagramBundle\TokenHandler\CookieToken
        instaphp_token_handler:
            class:            Oh\InstagramBundle\TokenHandler\TokenManager
            arguments:        [@instaphp_user_token_handler, @instaphp_cookie_token_handler]
    

您还可以实现自己的 TokenHandlerInterface 以将认证代码存储在其他位置,如会话等。

测试

@todo

致谢