php - Get results from Instagram API to use in Wordpress -


i have been reading on basic authentication on instagram client(app). gather on reading curl best option threads saying. found instagram php api wrapper on gihub dont think need go route need.

what trying this:

a function checks current users meta 'instagram_user' (instagram user id) , 'instagram_token' (access token).

if usermeta not set, meaning have not authorized client yet, shows link authorization url. click link, authorize app , return our site. need know how retrieve data once return can use add_user_meta save token , id user_meta tables.

//get current user $user_id = get_current_user_id(); $instagram_userid = get_user_meta($user_id, 'instagram_user', true); $access_token = get_user_meta($user_id, 'instagram_token', true);  if(!$access_token || !$instagram_userid){     echo '<p style="text-align:center;">you need authorize instagram in order see feed here.</p><p><a class="btn btn-success" href="https://api.instagram.com/oauth/authorize/?client_id=client-id-here&redirect_uri=http://localhost:8888&response_type=code" title="click here verify" style="display:block;margin:0 auto;">verify now</a>'; } else { //user authorized ?> <div id="user-instagram-feed"></div>     <script type="text/javascript">     jquery(document).ready(function($)){         var access_token = "access_token";            var user_id = "user_id";         var url = "https://api.instagram.com/v1/users/"+user_id+"?access_token="+access_token+"&callback=?";         $.getjson(url, function(data) {             $("#user-instagram-feed").append("<img src='"+data.data.profile_picture+"' />");         });     });       </script> <?php } 

where stuck once user authorizes app , returns our site, how access data object pull token , user id?

side note: should not make difference users feed in widget on buddypress install, not same users feed trying display why chose save database , run conditional see if exists user.

is mean haven't getting instagram_user , instagram_token value? sorry, english isn't good.

this need login instagram. have tried instagram php api library? assuming callback page same code wrote (you should create custom callback page, though). so, it's this.

note: not tested. never use lib.

require '../src/instagram.php'; use metzweb\instagram\instagram; if( !session_id() )session_start(); //check whether session isn't started  $instagram = new instagram(array(     'apikey'      => 'your_app_key',     'apisecret'   => 'your_app_secret',     'apicallback' => 'your_app_callback' //this code's url ));  $user_id = get_current_user_id();  //once user returned, token store (as wish) if (isset($_get['code']){ $data = $instagram->getoauthtoken($code); $token = $data->access_token; add_user_meta( $user_id, 'instagram_token', $token); }      //get current user $access_token = get_user_meta($user_id, 'instagram_token', true); $instagram->setaccesstoken($access_token); $user_ig = $instagram->getuser(); $profile_picture = $user_ig->data->profile_picture;  if(!$access_token || !$instagram_userid){     echo '<p style="text-align:center;">you need authorize instagram in order see feed here.</p><p><a class="btn btn-success" href="'.$instagram->getloginurl().'" title="click here verify" style="display:block;margin:0 auto;">verify now</a>'; } else { //user authorized ?> <div id="user-instagram-feed"></div>     <script type="text/javascript">     jquery(document).ready(function($)){             $("#user-instagram-feed").append("<img src='<?php echo $profile_picture; ?>' />");     });     </script> <?php } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -