我的目标是订阅我的应用程序并获取标签 love 的所有数据
class IndexController extends App_Controller_Default
{ 公共函数 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); 但它不起作用:(