Instagram public RSS feed - rss

I was wondering how ink361 was creating an Instagram RSS feed from a username.
Example feed: http://ink361.com/feed/user/snoopdogg
Blog post:
http://blog.ink361.com/post/23664609916/new-rss-instagram-feed-feature-on-ink361-com
Any insight would be appreciated.
Thanks.

Instagram has a publicly accessible RSS API, it's hard to find any information about it, but it works for tags (we do use it).
For tags the syntax is the following:
http://instagr.am/tags/some-tag-you-want-to-follow/feed/recent.rss
I'm not sure whether they have something similar for users' feeds, as I've said it's really hard to find information about it and it may disappear from a day to another in favor of the official API, but right now it works for tags.
Here's an official blog post about it (although it covers only tags): http://blog.instagram.com/post/8755963247/introducing-hashtags-on-instagram

#user2543857 's answer was good. Unfortunately, the structure of the Instagram data has changed. As of the date of posting this, this will work. Copy/paste into a file on your PHP server and use like: yoursite.com/instarss.php?user=name_of_instagram_user This will return valid XML/RSS feed.
EDIT!! Naturally, the output of the page/JSON has changed with instagram's new look/feel. Here is updated code (June, 2015):
<?php
if (!isset($_GET['user'])) {
exit('Not a valid RSS feed. You didn\'nt provide an Instagram user. Send one via a GET variable. Example .../instarss.php?user=snoopdogg');
}
header('Content-Type: text/xml; charset=utf-8');
$html = file_get_contents('http://instagram.com/'.$_GET['user'].'/');
$html = strstr($html, '{"static_root');
$html = strstr($html, '</script>', true);
//$html = substr($html,0,-6);
$html = substr($html, 0, -1);
$data = json_decode($html);
// print_r($data->entry_data->ProfilePage[0]->user->media->nodes);
$rss_feed = '<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel>';
$rss_feed .= '<title>'.$_GET['user'].'\'s Instagram Feed</title><atom:link href="http://'.$_SERVER['HTTP_HOST'].$_SERVER["REQUEST_URI"].'" rel="self" type="application/rss+xml" /><link>http://instagram.com/'.$_GET['user'].'</link><description>'.$_GET['user'].'\'s Instagram Feed</description>';
foreach($data->entry_data->ProfilePage[0]->user->media->nodes as $node) {
$rss_feed .= '<item><title>';
if(isset($node->caption) && $node->caption != '') {
$rss_feed .= htmlspecialchars($node->caption, ENT_QUOTES, ENT_HTML5);
} else {
$rss_feed .= 'photo';
}
// pubdate format could also be: "D, d M Y H:i:s T"
$rss_feed .= '</title><link>https://instagram.com/p/'.$node->code.'/</link><pubDate>'.date("r", $node->date).'</pubDate><dc:creator><![CDATA['.$_GET['user'].']]></dc:creator><description><![CDATA[<img src="'.$node->display_src.'" />]]></description><guid>https://instagram.com/p/'.$node->code.'/</guid></item>';
} // foreach "node" (photo)
$rss_feed .= '</channel></rss>';
echo $rss_feed;
?>
Actually, don't use the above code. I'll try to maintain this Gist in the future.
EDIT December 2016: I'm tired of chasing the every-changing Instagram output only to screen scrape it and have it change a few months later. I'd say just use the API.. If you are still interested in making an RSS feed from a user's page, this Gist should give you an idea of how to do it.

You can access the feed for any Instagram user using the /users/user-id/media/recent API endpoint. This endpoint requires an access_token which you can obtain by authorizing some user with Instagram (not necessarily the one you request the feed for). The process for receiving access_token is described here.
So what ink361 may be doing is get an access_token for themselves (their user on Instagram) and use that to make /users/user-id/media/recent requests for any other users' feeds. Simple as that.

Thanks to torvin for the tip.
Here is how you can get instagram images on your site without using the API.
Create json file from url and username (set this as a cron job, X times per day)
<?
$html = file_get_contents('http://instagram.com/username/');
$html = strstr($html, '["lib');
$html = strstr($html, '</script>', true);
$html = substr($html,0,-6);
file_put_contents("username.json",$html);
?>
Display a few images from json feed
<?
$json = file_get_contents('username.json');
$data = json_decode($json);
$img1 = $data[2][0]->props->userMedia[0]->images->standard_resolution->url;
$img2 = $data[2][0]->props->userMedia[1]->images->standard_resolution->url;
$img3 = $data[2][0]->props->userMedia[2]->images->standard_resolution->url;
print '<img src="'.$img1.'" />';
print '<img src="'.$img2.'" />';
print '<img src="'.$img3.'" />';
?>

If I were ink361, I would just crawl Instagram pages, parse HTML and turn it into RSS. No API, no authorization, no problems.

Unfortunately user2543857's solution above doesn't work anymore. Here's a version that works with the current profile page source though.
Create JSON file from URL and username (set this as a cron job, X times per day)
<?php
$json = file_get_contents('http://instagram.com/username');
$json = strstr($json, '{"entry_data"');
$json = strstr($json, '</script>', true);
$json = rtrim($json,';');
file_put_contents("username.json",$json);
?>
Display a few images from JSON feed
<?php
$json = file_get_contents('username.json');
$data = json_decode($json,true);
$img1 = $data['entry_data']['UserProfile'][0]['userMedia'][0]['images']['thumbnail']['url'];
$img2 = $data['entry_data']['UserProfile'][0]['userMedia'][1]['images']['thumbnail']['url'];
$img3 = $data['entry_data']['UserProfile'][0]['userMedia'][2]['images']['thumbnail']['url'];
print '<img src="'.$img1.'" />';
print '<img src="'.$img2.'" />';
print '<img src="'.$img3.'" />';
?>

You can get access to your rss feed for instagram by using their API. Their API uses oAuth2 for authentication. I use this method on my personal blog to pull in instagram pics on the homepage. I suspect this is how the ink361 site works. Ink361 will connect to the instagram api and prompt the user with a login via instagram box which they use to allow ink361 access to their instagram account. The ink361 site will cache the token received by instagram once authentication is successfull so they then can repeatedly go back to the instagram api on a periodic basis using the same token for authentication. Bingo you have access to the users data and you can create an rss feed from it.

The answer is simple.
To access user data you just must have valid access token.
The ink361 has an app in social network http://vk.com/app3225087 which stores authenticated users access tokens in db.
Its only left to find in db a valid one and get whatever user data you want

Related

How to access the response/redirect after stripe payment?

Im trying to sell videos on my website, hosted using wordpress. I have set up a Stripe account and been using "WP Simple Pay Lite for Stripe" Plugin on my website.
The problem that i'm facing is when I get a payment on stripe I manually send my customers the video that they have purchased. I was wondering if anyone has any advice on how I can automate the process by sending my customers the product once payment has been paid.
For this "WP Simple Pay Lite for Stripe" Plugin there is a successful payment URL redirect feature. That I was using before. How ever I noticed that you can view the successful payment redirect from the Developer Tools.
<input type="hidden" name="sc-redirect" value="https://wpsimplepay.com/demo-success-page/">
In this topic which is similar to yours the author suggests to use sc_after_charge hook. So your code will be:
add_action( 'sc_after_charge', 'sc_after_charge_example' );
function sc_after_charge_example( $charge_response ) {
if ( $charge_response->paid ) {
$url = 'https://wpsimplepay.com/demo-success-page/';
wp_redirect( $url );
exit;
}
}
I am not sure abou the response type and if its JSON, but in Stripe Docs it's a JSON.
As Stanimir Stoyanov said, you can use sc_after_charge but his code won't work because sc_after_charge returns Charge object, not JSON.
/**
* Sends video url to customer when payment is successful
* #param $response \Stripe\Charge
*/
function send_video_if_payment_successful( $response ) {
if ( $response->paid ) {
// Maybe check amount and or description to ensure it's same product
$file = 'http://url_to/file_to_attach.mp4'; // Video url
$subject = 'Find your video here - My store'; // Email subject
$msg = '
Thanks for buying...
yada yada yada...
Please find attached video.'; // Email message
$attachments = array( $file ); // Add attachment
$headers = 'From: My store <myname#example.com>' . "\r\n"; // Set yourself in From header
wp_mail( $response->receipt_email, $subject, $msg, $headers, $attachments ); // Send the mail
}
}
add_action( 'sc_after_charge', 'send_video_if_payment_successful' );
Here we first check if payment was successful, if yes, we the email the file to the user :)
If you plan to sell multiple products... You can set appropriate description and send different files for different descriptions accessible by $response->description
In the short code add success_redirect_url="https://wpsimplepay.com/demo-success-page" as an attribute
[stripe name="My Store" description="My Product" amount="1999" success_redirect_url="https://wpsimplepay.com/demo-success-page"]
Source: https://wpsimplepay.com/docs/shortcodes/stripe-checkout/
please use woocommerce download product
https://docs.woocommerce.com/document/digitaldownloadable-product-handling/
check this i hope it is helpfull

JSON API + wordpress URL

I'm using a small JSON API for URL shortener that I would like to integrate on all my Wordpress pages.
I know how to render the Wordpress page URL but what I don't know (due to no experience with APIs) is how to render the API result on the Wordpress page.
Here is the API call:
http://abc.net/api?api=123&url=LONGURL
Here is the API result:
{
"error":"0",
"short":"http://abc.net/ALIAS",
}
Here is the WP url that needs to replace the "LONGURL" above:
<?php echo get_permalink(); ?>
What I need is to show the "short" result.
Any ideas?
Assuming you've set allow_url_fopen to true in php.ini
function get_short_permalink() {
$permalink = get_permalink();
$response = file_get_contents('http://abc.net/api?api=123&url=' . $permalink);
$response = json_decode($response, true);
if($response['error'] == 0) {
return $response['short'];
}
return $permalink;
}
Then replace <?php echo get_permalink(); ?> with <?php echo get_short_permalink(); ?> in your templates.
What this function does:
gets the original permalink
sends a GET request to your API
transforms the response from a JSON string to a PHP array (see the docs for the bool $assoc parameter of json_decode)
returns the shortened link if the error code is 0, or the original link if not
You'll have to work with cURL if you can't (or don't want to) enable url_fopen.
Also, WordPress has a built-in wrapper over cURL that could simplify things a lot: wp_remote_get

Google Analytics API Automated Login

I have this panel that i'm developing at my company where i will show the user's information from Google Analytics but i don't want the user to authorize or log in with his account every time he comes to the panel.
What i would like to do is: on the first time using my panel he would connect his Google account and i would save some info and on the next time he connects at my panel i would use this saved info to log on his account so i can list the Analytics info without ask for his permission or list that info even if he's not connected on is Google account right now.
Basically i would log in his account automatically and permit the 'app' to show the information.
I already have some code that connects on the API if he is connected on is Google account, but when he's not i get the login screen where he has to provide his email e password.
What i have so far is this:
<?php
require_once 'Google/Client.php';
require_once 'Google/Service/Analytics.php';
session_start();
$client = new Google_Client();
$client->setApplicationName("Google Analytics PHP Starter Application");
$client->setClientId('KEY');
$client->setClientSecret('SECRET');
$client->setRedirectUri('RETURN URI');
$client->setScopes('https://www.googleapis.com/auth/analytics.readonly');
$client->setAccessType('offline');
$service = new Google_Service_Analytics($client);
if(isset($_GET['logout']))
{
unset($_SESSION['token']);
}
if(isset($_GET['code']))
{
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
if(isset($_SESSION['token']))
{
$client->setAccessToken($_SESSION['token']);
}
if($client->getAccessToken())
{
$props = $service->management_webproperties->listManagementWebproperties("12008145");//~all
print "<h1>Web Properties</h1><pre>" . print_r($props, true) . "</pre>";
$accounts = $service->management_accounts->listManagementAccounts();
//print "<h1>Accounts</h1><pre>" . print_r($accounts, true) . "</pre>";
$segments = $service->management_segments->listManagementSegments();
//print "<h1>Segments</h1><pre>" . print_r($segments, true) . "</pre>";
$goals = $service->management_goals->listManagementGoals("~all", "~all", "~all");
//print "<h1>Goals</h1><pre>" . print_r($goals, true) . "</pre>";
$_SESSION['token'] = $client->getAccessToken();
}
else
{
$authUrl = $client->createAuthUrl();
header("Location: " . $authUrl);
}
?>
Is there any way to do that ? I have looked for it around everywhere and couldn't find something near it.
In google Api's, when user authenticate the first time, you receive a CODE (which you are already getting i suppose). Use this code to get refresh token (lifetime is (always), until and unless, user revokes the permissions). Save this refresh token in Database for further use. Refresh token is used to get access token(lifetime is a short time, returned in the expires in argument). Access token is to give you access to your user's data for some time. You can keep using refresh token to get access token whenever you need to access your user's data.
Whenever you want to access user's data, use refresh token to get access token and then use that access token to get user's data.
In your case, you are using google api php client, you can use Methods in Client.php like:
getAccessToken()---to get refresh token the first time. When you call this method, you get back a json in a form: let this json name be $accessToken
$accessToken = {"access_token":"TOKEN", "refresh_token":"TOKEN", "token_type":"Bearer",
"expires_in":3600,"id_token":"TOKEN", "created":1320790426}
parse json to take refresh_token($refreshToken = $accessToken.refresh_token) and save it for later use.
setAccessToken($accessToken)---call this to set the OAuth access token.
refreshToken($refreshToken)---Fetches a fresh OAuth access token with the given refresh token.
For further clearity, look at Client.php and also read:
https://developers.google.com/accounts/docs/OAuth2WebServer

Cannot Authenticate Salesforce in a Wordpress Plugin

I'm getting an error (INVALID_SESSION_ID) when trying to send an authenticated GET request to Salesforce.com.
Here is the plug-in in its entirety, which basically just outputs the body of the REST response to whatever page has the [MembershipTables] shortcode:
if (!class_exists('WP_Http')) {
include_once(ABSPATH . WPINC . '/class-http.php');
}
// This is obviously the real username
$username = 'xxxx#xxxx.xxx';
// And this is obviously the real password concatonated with the security token
$password = 'xxxxxxxxxxxxxx';
function getMembershipTables() {
$api_url = 'https://na15.salesforce.com/services/apexrest/directory';
$headers = array('Authorization' => 'Basic ' . base64_encode("$username:$password"));
$args = array('headers' => $headers);
$request = new WP_Http;
$result = $request->request($api_url, $args);
$body = $result['body'];
echo "$body";
}
add_shortcode( 'MembershipTables', 'getMembershipTables' );
I should note that I can successfully hit this endpoint with Curl, though I use a session token I get from Salesforce using the old SOAP API to keep it equivalent (i.e., no client id/secret).
Am I doing something wrong with WP_Http? Or cannot I not authenticate a salesforce.com request using basic auth?
Thanks.
The salesforce API does not support Basic authentication, you need to call it with a sessionId. You can obtain a sessionId by various methods include interactive & programatic OAuth2 flows, and via a Soap login call.
Basis Interactive had a similar problem to solve. When I worked on the project I opted to to call the SalesForce CRM via the preset form plugin and a custom JS Cookie PHP Wordpress Plugin. We had this problem easily resolved by developing custom calls to SalesForce CRM via a getRequest in PHP passing data to the SalesForce CRM.
Test Site in Use:
http://newtest.medullan.com/wp/?page_id=3089
Here is the code and recycle the logical queries
Download Link:
http://basisinteractive.net/webdesign.html#wordpress

application loaded in iframe on facebook

I have an app loaded in iframe on facebook.
But after allow and redirected to my facekooksite from facebook authorization i cant fetch the "code" from the querrystring from within my code (because loaded in an iframe on facebook)
How will i be able to fetch the "code" parameter?
I guess you are following the server-side authentication flow. But since you are using Apps on Facebook, this flow will change since Facebook is sending a signed_request to your canvas iframe:
<?php
$app_id = "YOUR_APP_ID";
$canvas_page = "YOUR_CANVAS_PAGE_URL";
$auth_url = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page);
$signed_request = $_REQUEST["signed_request"];
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
$data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);
if (empty($data["user_id"])) {
echo("<script> top.location.href='" . $auth_url . "'</script>");
} else {
echo ("Welcome User: " . $data["user_id"]);
}
?>
Obviously when you are on Facebook, the user is either connected to your app or not so if he/she is not connected then you redirect them to the authentication URL.

Resources