How do I get Instagram posts from several accounts? - instagram

I would like to show the latest instagram posts from three different instagram users in one app. I control the instagram accounts, so it wouldn't be a problem to use APIs that require the user to accept access.
One method would be to add ?__a=1 at the end of their profile to get at json that contains this information, show the title as text in my app and load the picture from Instagram's CDN.
From what I can see, this isn't allowed by Instagram's terms, so I could easily see them banning the whole thing after some time.
Using Instagram's APIs (both Basic Display API or Graph) looks doubtful in an app, since they are based on tokens that should be kept server side.
Potentially I can configure a backend that does nothing but get the content, stores it with the single purpose of pushing it forward. I would think even this is against Instagram's terms, and sounds a bit over-kill.
Is there any methods I've missed?
(The Bot asked for some code, here's the JS I cannot use..)
function viewInsta(input_url) {
var url = input_url;
const p = url.split("/");
var t = '';
for (let i = 0; i < p.length; i++) {
if(i==2){
t += p[i].replaceAll('-', '--').replaceAll('.','-')+atob('LnRyYW5zbGF0ZS5nb29n')+'/';
} else { if(i != p.length-1){ t += p[i]+'/'; } else { t += p[i]; } }
}
// document.getElementById(this.id).src = encodeURI(t);
return '<img src="'+encodeURI(t)+'">';
}
var request = new XMLHttpRequest();
request.open("GET", "instagram.json", false);
request.send(null)
var my_JSON_object = JSON.parse(request.responseText);
var node_objects = my_JSON_object.graphql.user.edge_owner_to_timeline_media.edges;
node_objects.forEach(alert_function);
function alert_function(value){
var url_array = value.node.thumbnail_src.split('?');
var url = url_array[0];
document.getElementById("div1").innerHTML += value.node.thumbnail_src + viewInsta(value.node.thumbnail_src) + '<hr>';
console.log (value.node.thumbnail_src);
}

You'll need to use the Facebook Graph API, specifically Instagram, and do the calls from your backend.
https://developers.facebook.com/docs/instagram-api/reference/ig-user/media#get-media
This means you'll need to do oAuth and store the access tokens on your backend.
You should be able to get the posts with POST /{ig-user-id}/media

Related

Data From REST API In Azure

I have implemented REST API calls using a standalone c# console application. The API returns JSON which i'm deserializing and then storing it in the database.
Now i want to implement the entire logic in Azure platform so that it can invoked by passing start date and an end date and store location (it should run for three location) Below is the code:
static void Main()
{
MakeInventoryRequest();
}
static async void MakeInventoryRequest()
{
using (var client = new HttpClient())
{
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "5051fx6yyy124hhfyuscf34f57ce9");
// Request parameters
queryString["query.locationNumbers"] = "4638";
queryString["availableFromDate"] = "2019-01-01";
queryString["availableToDate"] = "2019-03-07";
var uri = "https://api-test.location.cloud/api/v1/inventory?" + queryString;
using (var request = new HttpRequestMessage(HttpMethod.Get, uri))
using (var response = await client.SendAsync(request))
{
var stream = await response.Content.ReadAsStreamAsync();
if (response.IsSuccessStatusCode == true)
{
List<Inventory> l1 = DeserializeJsonFromStream<List<Inventory>>(stream);
InsertInventoryRecords(l1);
}
if (response.IsSuccessStatusCode == false)
{
throw new Exception("Error Response Code: " + response.StatusCode.ToString() + "Content is: " + response.Content.ReadAsStringAsync().Result.ToString());
}
}
}
}
Please suggest the best possible design using Azure components
With the information in hand I think you have multiple options , you need to find out which works for you the best . You can use Cloud service to host the console app ( you will have to change it to worker role , Visual studio will help you to convert that ) . I am not sure about the load which you are expecting but you can always increase and decrease the instance and these can be deployed to different geographies .
I see that you are persisting the data , if you want to do that you can use many of the SQL offerings . For invoking the REST API you can also azure functions and ADF.
Please feel free to comment if you want any more details on the same.

User.Suspended always return false in octokit.net

I am using the following code to get a list of all GitHub Enterprise users, then I am trying to suspend those no longer in AD. The Suspend function works, but User.Suspended property always returns false.
var searhRequest = new SearchUsersRequest("type:user&page="+pageNumber+"&page_size=100");
githubUsers = await client.Search.SearchUsers(searhRequest);
client.User.Administration.Suspend(userId);
Yeah, I think the problem is that we were trying to cast the return value as a user when ultimately the call that this is making behind the scenes doesn't return that data. As a work around, I've just called the get user method to get the users after I've rounded up the original results.
It can probably be done better, but here's what I have right now
Task<SearchUsersResult> task;
List<User> users = new List<User>();
int page = 1;
do
{
task = github.Search.SearchUsers(new SearchUsersRequest("type:user&repos:>=0") { Page = page, PerPage = 500 });
task.Wait();
users.AddRange(task.Result.Items.ToList<User>());
page++;
}
while (users.Count < task.Result.TotalCount);
// Get all users by login (this calls the api once for every user you have)
var tasks = users.Select(u => github.User.Get(u.Login));
// Get all unsuspended users
var activeUsers = Task.WhenAll<User>(tasks).Result.Where<User>(u => !u.Suspended).ToList();
Note that in the result of the call doesn't include the "isSuspended" data (pulled from my local enterprise instance using fiddler and then sanitized)
{"login":"User1"
"id":45
"avatar_url":"http://github.com/avatars/u/45?"
"gravatar_id":""
"url":"http://github.com/api/v3/users/User1"
"html_url":"http://github.com/User1"
"followers_url":"http://github.com/api/v3/users/User1/followers"
"following_url":"http://github.com/api/v3/users/User1/following{/other_user}"
"gists_url":"http://github.com/api/v3/users/User1/gists{/gist_id}"
"starred_url":"http://github.com/api/v3/users/User1/starred{/owner}{/repo}"
"subscriptions_url":"http://github.com/api/v3/users/User1/subscriptions"
"organizations_url":"http://github.com/api/v3/users/User1/orgs"
"repos_url":"http://github.com/api/v3/users/User1/repos"
"events_url":"http://github.com/api/v3/users/User1/events{/privacy}"
"received_events_url":"http://github.com/api/v3/users/User1/received_events"
"type":"User"
"site_admin":false
"ldap_dn":"CN=User1
OU=CompanyDEVUsers
OU=Users
OU=Company
DC=Company
DC=com"
"score":1.0}

How do I post from Instagram to a Squarespace blog?

After a good amount of research today I figured it would be helpful if I wrote up what I have found to be a solid way to get Instagram posts automatically, not into a block, but directly into your blog on your foursquare blog (or other blogs that accept posts from email).
Prerequisites: A Gmail Account, and IFTTT account
Firstly in the settings for your blog turn on post by email. Then set up a trigger at IFTTT.com. The trigger is if a new photo is posted to your instagram send an email from your Gmail. The trigger is then set up to send the email to your GMail, subject can be whatever you'd like, I chose instagram: the body of the email is:
{{SourceUrl}} {{Caption}}
You then create a google script at script.google.com the script is: (must modify depending on your email address, subject you chose for email, and the email address you must send to for posting to your blog).
function sendCorrectEmail() {
var instagramThreads = GmailApp.search('from:(justinhenricks#gmail.com) to:(justinhenricks#gmail.com) subject:(instagram:)', 0, 25);
for(var i = 0; i < instagramThreads.length; i++) {
var messages = instagramThreads[i].getMessages();
for(var j = 0; j < messages.length; j++){
var body = messages[j].getPlainBody();
var urlEndIndex = body.indexOf(" ");
var url = body.substring(0, urlEndIndex);
var content = body.substring(urlEndIndex + 1, body.length - 1);
var newBody = "<center><img src='" + url + "' /><br /><br /><i>instagram: </i>" + content + " </center>";
GmailApp.sendEmail("pbm+justin-henricks+j4p937#squarespace.com", "", newBody);
}
}
//delete all threads
if(instagramThreads.length > 0) {
GmailApp.moveThreadsToTrash(instagramThreads);
}
};
Of course format the HTML to whatever you seem fit. The script simply checks your email for emails sent by you, to you, with a subject of instagram: it then takes the body of the email if it found one and separates the img URL from the content, it then formats those two variables into a little bit of HTML and sends a new email out to the address accepted by your blog.
Lastly, you're going to want to click Resources on the google script and add a trigger for the method to be executed every x amount of time. That way it will continuously check if there has been new instagram posts, and it will post them automatically.
I spent a few hours on this and although at first there seemed like there were less complicated ways to achieve this, there turned out not to be. If you are content with simply having a separate instagram block on your site SquareSpace can do this for you. I wanted my blog to contain my blog posts, and instagram posts all in one. This script can also very easily be modified to handle Twitter, Facebook etc all you would need to do is set up different IFTTT triggers and write new methods. Good luck!

Retrieve public statistics of video via youtube api

It's possible to obtain public statistics of video?
Using something like this i can get just total views of video and like count:
https://www.googleapis.com/youtube/v3/videos?part=statistics&key=API_KEY&id=ekzHIouo8Q4
It's possible to get those public statistics?
I found this question
Youtube GData API : Retrieving public statistics
But maybe something has changed?
The only API call under Version 3 of the API that will get you statistics is the
youtube.videos.list API
Try this API Explorer link to try:
https://developers.google.com/apis-explorer/#p/youtube/v3/youtube.videos.list?part=snippet%252C+statistics&id=Ys7-6_t7OEQ&maxResults=50&_h=2&
You can get those using Analytics API
Sample requests would help you understand.
Analytics API is a different service but libraries come in same package and you can use same authorization with adding "https://www.googleapis.com/auth/yt-analytics.readonly" scope
You would need to create YouTubeService object and can get search results for the keywords
YouTubeService youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
ApiKey = "dfhdufhdfahfujashfd",
ApplicationName = this.GetType().ToString()
});
var searchListRequest = youtubeService.Search.List("snippet");
searchListRequest.Q = "cute cats";
searchListRequest.MaxResults = 10;
var searchListResponse = await searchListRequest.ExecuteAsync();
var videoId = searchListResponse.Items.First().Id.VideoId is the unique id of the video
// Video Request
VideosResource.ListRequest request = new VideosResource.ListRequest(youTubeService, "statistics")
{
Id = videoId
};
VideoListResponse response = request.Execute();
if (response.Items.First() != null && response.Items.First().Statistics != null)
{
Console.WriteLine(response.Items.First().Statistics.ViewCount);
}

How can I tell if a web client is blocking advertisements?

What is the best way to record statistics on the number of visitors visiting my site that have set their browser to block ads?
Since programs like AdBlock actually never request the advert, you would have to look the server logs to see if the same user accessed a webpage but didn't access an advert. This is assuming the advert is on the same server.
If your adverts are on a separate server, then I would suggest it's impossible to do so.
The best way to stop users from blocking adverts, is to have inline text adverts which are generated by the server and dished up inside your html.
Add the user id to the request for the ad:
<img src="./ads/viagra.jpg?{user.id}"/>
that way you can check what ads are seen by which users.
You need to think about the different ways that ads are blocked. The first thing to look at is whether they are running noscript, so you could add a script that would check for that.
The next thing is to see if they are blocking flash, a small movie should do that.
If you look at the adblock site, there is some indication of how it does blocking:
How does element hiding work?
If you look further down that page, you will see that conventional chrome probing will not work, so you need to try and parse the altered DOM.
AdBlock forum says this is used to detect AdBlock. After some tweaking you could use this to gather some statistics.
setTimeout("detect_abp()", 10000);
var isFF = (navigator.userAgent.indexOf("Firefox") > -1) ? true : false,
hasABP = false;
function detect_abp() {
if(isFF) {
if(Components.interfaces.nsIAdblockPlus != undefined) {
hasABP = true;
} else {
var AbpImage = document.createElement("img");
AbpImage.id = "abp_detector";
AbpImage.src = "/textlink-ads.jpg";
AbpImage.style.width = "0";
AbpImage.style.height = "0";
AbpImage.style.top = "-1000px";
AbpImage.style.left = "-1000px";
document.body.appendChild(AbpImage);
hasABP = (document.getElementById("abp_detector").style.display == "none");
var e = document.getElementsByTagName("iframe");
for (var i = 0; i < e.length; i++) {
if(e[i].clientHeight == 0) {
hasABP = true;
}
}
if(hasABP == true) {
history.go(1);
location = "http://www.tweaktown.com/supportus.html";
window.location(location);
}
}
}
}
I suppose you could compare the ad prints with the page views on your website (which you can get from your analytics software).

Resources