Commit a52fe0e5 by halweg

feat : instagram feed拉取

parent 48f199a1
......@@ -72,6 +72,8 @@ class ApiAddress extends Template
"?client_id={$this->getAppid()}&redirect_uri={$this->redirectUri()}&scope=user_profile,user_media&response_type=code";
}
public function getMediaUrl($token, $uid): string
{
return self::INSTAGRAM_GRAPH_API_URL."/v16.0/{$uid}/media?access_token={$token}&fields=caption,id,is_shared_to_feed,media_type,media_url,permalink,thumbnail_url,timestamp,username";
}
}
\ No newline at end of file
<?php
namespace Joshine\InstagramFeed\Block;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\View\Element\Template;
use Magento\Store\Model\ScopeInterface;
class MediaFeed extends Template {
protected $request;
protected $_template = 'Joshine_InstagramFeed::mediafeed.phtml';
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $_objectManager;
/**
* @var ApiAddress
*/
private $apiAddress;
private $_curlClient;
/**
* @var \Magento\Framework\Json\EncoderInterface
*/
private $jsonEncoder;
/**
* @var \Magento\Framework\Json\Decoder
*/
private $jsonDecoder;
public function __construct(
Template\Context $context,
\Magento\Framework\ObjectManagerInterface $objectManager,
\Magento\Framework\App\Request\Http $request,
ApiAddress $apiAddress,
\Magento\Framework\HTTP\Client\Curl $curl,
\Magento\Framework\Json\EncoderInterface $jsonEncoder,
\Magento\Framework\Json\Decoder $jsonDecoder,
array $data = []
) {
parent::__construct($context, $data);
$this->request = $request;
$this->_objectManager = $objectManager;
$this->apiAddress = $apiAddress;
$this->_curlClient = $curl;
$this->jsonEncoder = $jsonEncoder;
$this->jsonDecoder = $jsonDecoder;
}
public function getCurlClient()
{
return $this->_curlClient;
}
public function getMedia() {
$uid = $this->_objectManager->get(ScopeConfigInterface::class)
->getValue(
'joshine_instagram_feed/general/user_id',
ScopeInterface::SCOPE_STORE
);
$token = $this->_objectManager->get(ScopeConfigInterface::class)
->getValue(
'joshine_instagram_feed/general/access_token',
ScopeInterface::SCOPE_STORE
);
$url = $this->apiAddress->getMediaUrl($token, $uid);
$this->getCurlClient()->get($url);
$this->getCurlClient()
->setOptions([
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false
]);
if ($this->getCurlClient()->getStatus() != 200) {
return [];
}
return $this->jsonDecoder->decode($this->getCurlClient()->getBody());
}
}
\ No newline at end of file
......@@ -36,7 +36,7 @@ class Redirect extends Action
{
$this->_curlClient = $curl;
$this->_configWriter = $configWriter;
$this->_apiAddress = $apiAddress;
$this->_apiAddress = $apiAddress;
$this->_cacheTypeList = $cacheTypeList;
parent::__construct($context);
}
......@@ -68,7 +68,7 @@ class Redirect extends Action
return;
}
$userId = $oauthRes['user_id'];
$longLifeToken = $oauthRes['access_token'];
$longLifeToken = $longToken['access_token'];
$this->_configWriter->save("joshine_instagram_feed/general/user_id", $userId);
$this->_configWriter->save("joshine_instagram_feed/general/access_token", $longLifeToken);
$this->_cacheTypeList->cleanType(\Magento\Framework\App\Cache\Type\Config::TYPE_IDENTIFIER);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment