Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
joshine
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
joshine
Commits
a52fe0e5
Commit
a52fe0e5
authored
Apr 14, 2023
by
halweg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat : instagram feed拉取
parent
48f199a1
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
4 deletions
+91
-4
app/code/Joshine/InstagramFeed/Block/ApiAddress.php
+5
-2
app/code/Joshine/InstagramFeed/Block/MediaFeed.php
+84
-0
app/code/Joshine/InstagramFeed/Controller/Adminhtml/OAuth/Redirect.php
+2
-2
app/code/Joshine/InstagramFeed/view/frontend/templates/mediafeed.phtml
+0
-0
No files found.
app/code/Joshine/InstagramFeed/Block/ApiAddress.php
View file @
a52fe0e5
...
...
@@ -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
app/code/Joshine/InstagramFeed/Block/MediaFeed.php
0 → 100644
View file @
a52fe0e5
<?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
app/code/Joshine/InstagramFeed/Controller/Adminhtml/OAuth/Redirect.php
View file @
a52fe0e5
...
...
@@ -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
);
...
...
app/code/Joshine/InstagramFeed/view/frontend/templates/mediafeed.phtml
0 → 100644
View file @
a52fe0e5
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment