How do I get the shortcode for an Instagram media item to later embed the picture? - api

I'd like to display Instagram photos matching particular tags on my site. I don't see a way to search for all tags over all time, so I am implementing a timer that periodically checks /tags/tag-name/media/recent for my desired tags. Then I am caching the .id attribute of any as-yet-unseen media, so I can still have access to that item if and when /tags/tag-name/media/recent no longer returns that item.
Now I am ready to embed the images on my site, but I think saving .id is mistaken. The second available embed endpoint - /p/shortcode/media - looks close. It issues a redirect to the image, which will suffice for my task, but it wants a 'shortcode', not an id.
How do I get this shortcode? There is no .shortcode attribute on the media objects returned from /tags/tag-name/media/recent. Should I use a regex to parse the .link attribute, assuming that the link will take the form http://instagr.am/p/shortcode/? Or is there a better technique to remember and later display images that match my desired tags?

Preferring regex solution over String.split, this is what I ended up doing:
//expecting http://instagr.am/p/BWl6P/
var linkrx = /\/p\/([^\/]+)\/$/;
// find /p/, then 1 or more non-slash as capture group 1, then / and EOL
if(igPic.link.match(linkrx) !== null){
var shortcode = igPic.link.match(linkrx)[1];
};

No other way, just use .split() from the link attribute. This will give you the shortcode:
link.split("/")[4]

/p/([^/]+)(/.)*$
this pattern match also links like:
https://instagram.com/p/6H_CiIrdKn/?taken-by=7imet4
https://instagram.com/p/6H_CiIrdKn

This will always return the last component of a path:
'http://instagr.am/p/D/'.replace(/\/$/i, '').split("/").pop()
So http://instagr.am/p/D/ becomes D
tl;dr
Remove any trailing slash (//$/i, a/b/c/ → a/b/c)
Split by / (a/b/c → [a,b,c])
Get the last item in the [a,b,c] array (.pop(), [a,b,c] → c)

Related

why is the slug not saved in Strapi?

there is a video content type field in which there is a link slug, and when a new video is created, in the get request we get a null slug. tell me what's the matter. didn't install slugify
docs
getting stuck at getting {slug : null} after api call in strapi?
ok, this is what I did
I made a variable before POST request based on one of my form fields (eg:name field)
my formValues is an object with values of form fields like this
formValues = {name:"whatever" , decsription:"whatever"}
make a variable:
const slug = formValues.name.split(" ").join("-") + "-" + Math.random();
now we might have same names, so that's why I used a random value (you might want to use uuid or something like that)
then you send it like this
const res = await axios.post(`${API_URL}/api/events`,{...formValues, slug });
// you may not need to send an object with the shape like this
// but the point is you concat your custom slug to the object you want to send
notice I'm adding a custom slug from frontend which is somehow random but based off of one of the fields, but it doesn't really matter, right now strapi does not have any documentation about this common problem, it seems like the best solution might be usingstrapi-plugin-slugify but if that didn't work for you feel free to use my solution

Extract portion of HTML from website?

I'm trying to use VBA in Excel, to navigate a site with Internet explorer, to download an Excel file for each day.
After looking through the HTML code of the site, it looks like each day's page has a similar structure, but there's a portion of the website link that seems completely random. But this completely random part stays constant and does not change each time you want to load the page.
The following portion of the HTML code contains the unique string:
<a href="#" onClick="showZoomIn('222698519','b1a9134c02c5db3c79e649b7adf8982d', event);return false;
The part starting with "b1a" is what is used in the website link. Is there any way to extract this part of the page and assign it as a variable that I then can use to build my website link?
Since you don't show your code, I will talk too in general terms:
1) You get all the elements of type link (<a>) with a Set allLinks = ie.document.getElementsByTagName("a"). It will be a vector of length n containing all the links you scraped from the document.
2) You detect the precise link containing the information you want. Let's imagine it's the 4th one (you can parse the properties to check which one it is, in case it's dynamic):
Set myLink = allLinks(3) '<- 4th : index = 3 (starts from zero)
3) You get your token with a simple split function:
myToken = Split(myLink.onClick, "'")(3)
Of course you can be more synthetic if the position of your link containing the token is always the same, like always the 4th link:
myToken = Split(ie.document.getElementsByTagName("a")(3).onClick,"'")(3)

REST API: How to search for other attribute

I use node.js as REST API.
There are following actions available:
/contacts, GET, finds all contacts
/contacts, POST, creats new contact
/contacts/:id, GET, shows or gets specifiy contact by it's id
/contacts/:id, PUT, updates a specific contact
/contacts/:id, DELETE, removes a specific contact
What would now be a logic Route for searching, quering after a user?
Should I put this to the 3. route or should I create an extra route?
I'm sure you will get a lot of different opinions on this question. Personally I would see "searching" as filtering on "all contacts" giving:
GET /contacts?filter=your_filter_statement
You probably already have filtering-parameters on GET /contacts to allow pagination that works well with the filter-statement.
EDIT:
Use this for parsing your querystring:
var url = require('url');
and in your handler ('request' being your nodejs http-request object):
var parsedUrl = url.parse(request.url, true);
var filterStatement = parsedUrl.query.filter;
Interesting question. This is a discussion that I have had several times.
I don't think there is a clear answer, or maybe there is and I just don't know it or don't agree with it. I would say that you should add a new route: /contacts/_search performing an action on the contacts list, in this case a search. Clear and defined what you do then.
GET /contacts finds all contacts. You want a subset of all contacts. What delimiter in a URI represents subsets? It's not "?"; that's non-hierarchical. The "/" character is used to delimit hierarchical path segments. So for a subset of contacts, try a URI like /contacts/like/dave/ or /contacts/by_name/susan/.
This concept of subsetting data by path segments is for more than collections--it applies more broadly. Your whole site is a set, and each top-level path segment defines a subset of it: http://yoursite.example/contacts is a subset of http://yoursite.example/. It also applies more narrowly: /contacts/:id is a subset of /contacts, and /contacts/:id/firstname is a subset of /contacts/:id.

What is the maximum number of url parameters that can be added to the exclusion list for google analytics

I set up a profile for Google Analytics. I have several dozen url parameters that various pages use and I want to exclude. Luckily, google has a field you can modify under the general profile settings [Exclude URL Query Parameters:]. Of the several dozen items I have they are all working, and not being considered part of the URL. Except for the parameter propid
I added propid to the comma separated list on Monday. But, everyday when I check GA, sure enough they are coming through with that parameter still attached.
So, am I trying to exclude too many parameters? I couldn't find any documentation on GA's site to say there was a limit.
here is the exact content of the exclude URL Query parameter field
There reason there are so many is the bh before me didn't know the difference between get/post.
propid,account,pp,kw1,kw2,kw3,sortby,page,msg,sd,ed,ea,ec,sc,subname,subcode,sa,qc,type,code,propid,acct,minbr,maxbr,minfb,maxfb,minhb,maxhb,minrm,maxrm,minst,maxst,minun,maxun,minyb,maxyb,minla,maxla,minba,maxba,minuc,maxuc,card,print,year,type
update
I thought after more time had passed the "bad data" would fall of of GA. But as of yesterday it is still reporting on the propid querystring value despite adding that as well as other variables to the exclude list.
update2
I found this post on google https://www.google.com/support/forum/p/Google+Analytics/thread?tid=72de4afc7b734c4e&hl=en
It reads that the field only allows 255 char, Ok. Problem Solved. Except my field of values is only 247 charcters.. ARGGGHH!
*Update 3 *
So Here is the code I've added to the googleAnalytics.asp include page that goes at the top of everyone of my asp classic pages. Can anyone see a flaw in the design? I don't care about ANY query string info. (it could have been named *.inc, but I like having intellisense working)
<script type="text/javascript">
<% GAPageDisplayName = REQUEST.ServerVariables("PATH_INFO") %>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-20842347-1']);
_gaq.push(['_setDomainName', '.sc-pa.com']);
<% if GAPageDisplayName <> "" then %>
_gaq.push(['_trackPageview','<%=GAPageDisplayName %>']);
<% else %>
_gaq.push(['_trackPageview']);
<% end if %>
(function () {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
Update 4
I'll only accept an answer if you will include something talking to the original question. My question was very specific, I wanted to know exactly the number of characters google allows. Everything I included in my original question body was simply to backfill the question to put everything in context.
Might I suggest an alternate solution to the reliance on manually excluding all of these (and feasibly any string ever used)?
I'd suggest passing a parameter to the trackPageView function to 'force' the recording of a manually/programatically set 'page name' value.
Whereas by default, GA records/defines a page based on a unique URL, the inclusion of a pagename parameter would associate all pageviews of a page with that parameter as pageviews to a single page.
For example, standard GA pageview code looks like this: _gaq.push(['_trackPageview']);, whereas the inclusion of a specific page name looks like this: _gaq.push(['_trackPageview', 'Homepage']);. With the latter, presuming that the homepage is at www.site.com, regardless of how that page is accessed GA will always consolidate all pageview stats for it as 'Homepage'. So, www.site.com/index.php, www.site.com/?a=b and www.site.com/?1=2&x=y will always report as 'Homepage' as if it was one page.
The only drawback here is that you need to be incredibly careful around any occurences of pagination, nested pages, content swapping, site search, or any functionality which may in fact rely on the use of query strings; you may need to consider some logic on how the page name values are output, rather than attempting to define on a per-page basis depending on the site of your site(s).
Hope that's helpful!
Do you realize that you have propid listed twice in the exclusion field? Once at the beginning and then again about one-third of the way through. That's the only thing that stands out to me. See what happens if you remove either of these.
You also have type duplicated, so if the above fixes the problem for propid, also consider removing the second type.
Google limits the characters in the "Exclude Url Query" field (2048 characters max), not the number of queries. I had the same issue you're having and what I discovered was that I had populated my query string parameter list based on the pagenames in my pages report. Well those pagenames first pass through a view-level lowercase filter that I have set up. And since the "Exclude URL Query" field is case sensitive, some of the parameters were getting through. Hopefully this helps.

Get id of file upload control

I am trying to find the name of ID of the input item that coresponds to the
file that is being uploaded...
<input type="file" id="FUtxtval1" name="FUtxtval1"/>
iterating over input items to find the first file input field:
function FindFirstFileFieldId()
{
var inputFields = document.getElementsByTagName("input")
for(var i=0;i<inputFields.length;i++)
{
if(inputFields[i].type=="file")
return inputFields[i].id;
}
}
The ID of the element is simply "FUtxtval1" (whatever is in the ID tag)
--
For JavaScript you can access this by using
var element = document.getElementById('FUtxtval1');
So you could then do something like
document.element.disabled=true;
--
For jQuery (Also JavaScript) you would use
$('#FUtxtval1').whatever
--
For PHP you would use
$_POST['FUtxtval1']
Assuming this is part of a form
For PHP if you actually want the file you use the handle
$_FILES['FUtxtval1']['whateverwanted'];
See http://www.tizag.com/phpT/fileupload.php
If the problem is that there may be many input tags on the form, and you're interested in discovering which one is specifically used for uploading files, this bit of jQuery code would accomplish that:
var id = $('input[type=file]').attr('id');
If the problem is that you know the element's ID but do not know the name of the field, you can use:
var name = $('#FUtxtval1').attr('name');
If you're hoping to find out the filename of the file your visitor has chosen in that field through JavaScript, you're stuck. JavaScript does not get any access to that information. You'll have to submit the form and let a server-side script determine the filename at that time.
If I understand correctly, you are trying to obtain the id of the uploaded file using javascript? If so, you will have to process the uploaded file using php ($_FILES['FUtxtval1']) and then print the id to a javascript variable.
Is that what you wanted?
If not, update your q to provide a bit more info about what you are trying to achieve.