私の目標は、アプリケーションのサブスクリプションを作成し、タグ love のすべてのデータを取得することです
class IndexController extends App_Controller_Default
{ public function indexAction() { $data = $this->_getSubscriptionTag(); Zend_Debug::dump($data); }
public function realtimecallbackAction()
{
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$allParams = $this->_getAllParams();
$dataFile = ROOT_DIR.'/data.txt';
file_put_contents($dataFile, implode(',',$_GET).implode(',',array_keys($_GET)));
if(isset($_GET['hub_challenge'])){
$challenge = $_GET['hub_challenge'];
$file = ROOT_DIR.'/json.txt';
$json = $this->_challenge($challenge);
file_put_contents($file, $json);
}
$request = $this->getRequest();
if($request->isPost()){
$filePostData = ROOT_DIR.'/postdata.txt';
$postdata = file_get_contents("php://input");
file_put_contents($filePostData, $postdata, FILE_APPEND | LOCK_EX);
}
}
protected function _getSubscriptionTag($verifyToken='')
{
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => array(CURLOPT_FOLLOWLOCATION => true),
);
$uri = 'https://api.instagram.com/v1/subscriptions/';
$request = $this->getRequest();
$callbackUrl= $request->getScheme().'://'.$request->getHttpHost().$request->getBaseUrl().'/index/realtimecallback';
$client = new Zend_Http_Client();
$client->setUri($uri);
$client->setConfig($config);
$client->setMethod(Zend_Http_Client::POST);
$client->setParameterPost('client_id', 'my_id');
$client->setParameterPost('client_secret', 'my_secret');
$client->setParameterPost('object', 'tag');
$client->setParameterPost('aspect', 'media');
$client->setParameterPost('object_id', 'love');
$client->setParameterPost('verify_token', $verifyToken);
$client->setParameterPost('callback_url', $callbackUrl);
$response = $client->request();
$httpCode = $response->getStatus();
$httpHeaders = $response->getHeaders();
$httpBody = $response->getBody();
$data = array();
try{
$data = Zend_Json_Decoder::decode($httpBody,Zend_Json::TYPE_ARRAY);
}
catch(Exception $e){
$data['error_type'] = 'malformed json';
$data['error_message'] = $e->getMessage();
}
var_dump($client->getLastRequest());
return $data;
}
protected function _challenge($challenge)
{
$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => array(CURLOPT_FOLLOWLOCATION => true),
);
$uri = 'https://api.instagram.com/v1/subscriptions/';
$client = new Zend_Http_Client();
$client->setUri($uri);
$client->setConfig($config);
$client->setParameterGet('challenge', $challenge);
$client->setParameterGet('client_id', 'my_id');
$client->setParameterGet('client_secret', 'my_secret');
$response = $client->request();
$httpCode = $response->getStatus();
$httpHeaders = $response->getHeaders();
$httpBody = $response->getBody();
return $httpBody;
}
}
json.txt ファイルで {"meta":{"code":200},"data":[]} を取得し、リクエストを行うと https://api.instagram.com/v1/subscriptions?client_secret=CLIENT -SECRET&client_id=CLIENT-ID 私も同じ結果になりました どちらに向いたらいいのかわかりません :( 助けていただけますか?
$client->setParameterGet('verify_token', $challenge); も試しました。しかし、それは機能しません:(