I need to add meta headers to URLRequest in flex3 - javascript

I am writing a flex3 tool for our uber-geeks. The tool is for futzing around with sharing URLs to various various social sites.
private function submitRequest(evt:Event):void {
var requestURL:URLRequest = new URLRequest(constructURL());
requestURL.method=URLRequestMethod.POST;
var header:URLRequestHeader = new URLRequestHeader("og:title", "petertitle");
requestURL.requestHeaders.push(header);
navigateToURL(requestURL,"_blank");
}
I want allow the developer to manipulate the following meta headers in the outgoing html request when navigateToURL() is called.
<meta property="og:title" content=title" />
<meta property="og:description" content="description" />\
<meta property="og:image" content="......" />
<meta property="og:video" content="......"/>
<meta property="og:video:height" content="640" />
<meta property="og:video:width" content="480" />
Unfortunately google is not showing me any example of how to add the above meta headers to my instance of URLRequest in flex. AND the new URLRequestHeader is blowing up.
ArgumentError: Error #2096: The HTTP request header og:title cannot be set via ActionScript.
at global/flash.net::navigateToURL()
Can someone point me at an example of putting the meta headers into a URLRequest?
additional
Looks like I am in a catch 22 situation.
I wrote the app to run in a flash player.
apparently the flash apps run from flashbuilder are not permitted to perfom http PUT method operations. it alwasy does GET
flash apps run from flashbuilder will not write headers on http GET calls.
But I am still not finding a way to add an http "meta" header tag in flex... perhaps adobe air.
Current work around.
I can call an external javascript function that will do a post, but however the XmlHttpRequest infrastructure only want to setRequestHeader(key,value), and seems to need to be from a very specific list of strings. setRequestHeader("foo","bar") did not add a foo header in my outgoing request.
There does not seem to be a way to add the header meta tag. via javascript. Or at lease I am not finding it off of google.
Hoping someone can now point me at how to do that?????

Do either of these help (appears the first one is particularly relevant, otherwise in the second a work-around is offered):
How can i send custom headers with URLRequest
Custom headers possible with URLRequest/URLStream using method GET?

What a pain. I would have thought someone would have run into this before and posted such a solution
setRequestHeader(arg1, arg2) ouptputs "< arg1 arg2 />" in the outgoing http request
so if I
xmlhttp.setRequestHeader("meta","property=\"og:description\" content=\"description\"");
then the outing html
<head>
....
<meta property="og:description" content="description"/>
....
</head>
<body>
....
</body>

Related

Problem with getting Instagram hashtag json without api into google sheets

I'm trying to get a hashtag JSON back from Instagram to google sheets. I get the JSON if I put the URL in a browser but not using google sheets script (it used to work in the past).
This is my code:
//Trying to bring back json from instagram
var tag = 'trivia';
var url = "https://www.instagram.com/explore/tags/"+tag+"/?__a=1";
var response = UrlFetchApp.fetch(url).getContentText();
Logger.log(response);
I get this:
[20-06-21 12:01:29:962 IDT] <!DOCTYPE html>
<html lang="en" class="no-js not-logged-in client-root">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>
Login • Instagram
</title>...
instead of this (when I put the same url in a browser- https://www.instagram.com/explore/tags/trivia/?__a=1): which is what I actually need btw to get in google sheets.
{"graphql":{"hashtag":{"id":"17841563248119719","name":"trivia","allow_following":true,"is_following":false,"is_top_media_only":false,"profile_pic_url":"https://instagram.fsdv3-1.fna.fbcdn.net/v/t51.2885-15/e15/s150x150/103649320_140557634281171_6362475220936910641_n.jpg?_nc_ht=instagram.fsdv3-1.fna.fbcdn.net&_nc_cat=107&_nc_ohc=QVtIBqOksWoAX9m12su&oh=fcaa18b44873d0b30d46e6c3369535c1&oe=5F1930BA","edge_hashtag_to_media":{"count":1284222,"page_info":{"has_next_page":true,"end_cursor":"QVFBdkxFeVcxRkFtVjVPaWdNZDhQeHRobHo0dlVfdjhtekVwazRTcjBIOXlwb0NqRndwaDZPZ195ZFdRd2t5RjU1OThiVExXLV9iLU5YUlkwSk5BUmE2LQ=="},"edges":[{"node":{"comments_disabled":false,"__typename":"GraphSidecar","id":"2336312505423207882","edge_media_to_caption":{"edges":[{"node":{"text":"Information about the movie:\n1. Director:\u00a0James Cameron\n2. Box office:\u00a0279 crores\u00a0\n3. Budget:\u00a023.7 crores\u00a0\n4. Film series:\u00a0Avatar Series\n5. IMDB: 7.8/10\n#avatar\u00a0#no.1movie\u00a0#jamescameron\u00a0#trivia\u00a0#facts#didyouknow\u00a0#information\u00a0#actors\u00a0#like\u00a0#follow#horrormovies\u00a0#fashion\u00a0#instamovies\u00a0#entertainment#moviereview\u00a0#bluray\u00a0#series\u00a0#photooftheday\u00a0#dvd\u00a0#bhfyp#marvel\u00a0#moviestar\u00a0#acting\u00a0#action\u00a0#movietime\u00a0#filmes#peliculas\u00a0#theatre\u00a0#oscars\u00a0#moviequotes"}}]},"shortcode":"CBsP9hqDZ3K","edge_media_to_comment":{"count":0},"taken_at_timestamp":1592730175,"dimensions":{"height":1080,"width":1080},"display_url":"https://instagram.fsdv3-1.fna.fbcdn.net/v/t51.2885-15/e35/104434100_280716426462541_3340933663299493770_n.jpg?_nc_ht=instagram.fsdv3-1.fna.fbcdn.net&_nc_cat=101&_nc_ohc=wYDWOpszIK0AX8sTi3N&oh=980538cb2e588f4467f0769ebae0c30e&oe=5F187460","edge_liked_by":{"count":6},"edge_media_preview_like":{"count":6},"owner":{"id":"37570480318"},"thumbnail_src":"https://instagram.fsdv3-1.fna.fbcdn.net/v/t51.2885-15/sh0.08/e35/s640x640/104434100_280716426462541_3340933663299493770_n.jpg?_nc_ht=instagram.fsdv3-1.fna.fbcdn.net&_nc_cat=101&_nc_ohc=wYDWOpszIK0AX8sTi3N&oh=97756e538cc662343493f9c6588fdfe2&oe=5F17CA66","thumbnail_resources":[{"src":"https://instagram.fsdv3-1.fna.
please help and please don't suggest getting an api which is a nightmare - I don't need that many queries anyway
There are two things that you are using.
browser
is google sheets script.
The reason why you are getting error is Instagram bot which actually tracks your IP when you make a request to it. When you are logged into your browser and request this https://www.instagram.com/explore/tags/"+tag+"/?__a=1 then you will always get data without being blocked.
But now, after the deprecation of old Instagram developer tool the rate limit of endpoints have reduced to 200 per hour. You get blocked because you cross the limit and Instagram bot takes time to reset your limit again.
It may take 2-3 days or more depending on frequency of getting blocked.
Yhe solution is if you properly apply session and cookies to request headers then it will surely help you.

Google Analytics blocked in IFrame due to "SameSite" & "Secure" setting of cookies

We're running a service on our-site.com. Our customers can either use the service "stand alone" by simply linking from their-site.com to our-site.com/customer-service or by embedding our service via iFrame into their-site.com. Imagine visiting GMaps directly vs. seeing it embedded in an IFrame.
Visiting "foreign" page with our service in IFarme
Beginning with Chrome 80 (i guess) our Google Analytics stopped working when the service runs inside the iFrame. Chrome is giving me this (quite clear) message:
A cookie associated with a cross-site resource at http://our-site.com/ was set without the SameSite attribute. It has been blocked, as Chrome now only delivers cookies with cross-site requests if they are set with SameSite=None and Secure. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
Also I don't see anything in the GA realtime overview if I visit their-site.com with our our-site.com/customer-service embedded in the iFrame.
If I manually disable the 2 features same-site-by-default-cookies & cookies-without-same-site-must-be-secure in chrome://flags and visit their-site.com with our-site.com/customer-service embedded in the iFrame I do see the page visit in the GA realtime overview.
Visiting our service "stand alone"
When directly visiting our-site.com/customer-service GA is still working just fine:
No warnings in dev tools
Multiple cookies associated to GA are shown in dev tools > applications tab
I can see page visits in the GA realtime overview
Neither of the cookies has the Secure or SameSite value set (all "blank")...
Question
Is there anything I can do to make GA work again when running inside an iFrame on a foreign domain?
Example code
I just created a very simple test environment which also shows the issues described above:
our-site.com/customer-service
<html lang="en">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={tracking-id}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() { dataLayer.push(arguments); }
gtag("js", new Date());
gtag("config", "{tracking-id}");
</script>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>our site service</title>
</head>
<body>our-site.com/customer-service</body>
</html>
their-site.com
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>their-site.com</title>
</head>
<body>
<iframe src="https://www.our-site.com/customer-service" style="width: 500px; height: 500px;"></iframe>
</body>
</html>
Even this very simple example shows the behavior described above, where opening our-site.com/customer-service directly, shows data in the GA realtime overview and opening their-site.com doesn't...
Answer from the Google tag manager support forum:
When accessing a first-party cookie (_ga) in a third-party context (the iframe), one has to explicitly add cookieFlags with the value samesite=none;secure.
Detailed description for various scenarios can be found at this blogpost.

LinkedIn stripping parameters from the share button url

I'm adding a LinkedIn share button to my site. The URL that needs to be shared includes a parameter, but LinkedIn is stripping the parameter from the URL. Any way to get around this?
I've tried using a custom share URL e.g.
http://www.linkedin.com/shareArticle?mini=true&url=https://stackoverflow.com/questions/10713542/how-to-make-custom-linkedin-share-button/10737122&title=How%20to%20make%20custom%20linkedin%20share%20button&summary=some%20summary%20if%20you%20want&source=stackoverflow.com
I've also tried using their share plugin e.g.
<script src="https://platform.linkedin.com/in.js" type="text/javascript">lang: en_US</script>
<script type="IN/Share" data-url="https://website.com/?par=1"></script>
Neither option is working for me. The URL just defaults to the root domain.
LinkedIn no longer supports those parameters.
2010:
https://www.linkedin.com/cws/share?url={url}
2016:
https://www.linkedin.com/shareArticle?url={url}&title={title}&summary={text}&source={provider}
2020:
https://www.linkedin.com/sharing/share-offsite/?url={url}
Unfortunately, we will have to survive with only a url parameter.
Source: Official Microsoft LinkedIn Share API Docs.
But, if you want to show a preview of some site info on the share page, before the user clicks to share it, you can use og: tags...
<meta property='og:title' content='Title of the article"/>
<meta property='og:image' content='//media.example.com/ 1234567.jpg"/>
<meta property='og:description' content='Description that will show in the preview"/>
<meta property='og:url' content='//www.example.com/URL of the article" />
Source: LinkedIn Developer Docs: Making Your Website Shareable on LinkedIn.
And when you're all done: Test it with the LinkedIn Post Inspector.

How do I prevent caching on a website?

Within a website in development, we have it templated as a master page that contains the head of the webpage, then a header and body div that loads in content dynamically. Basically, I'm trying to prevent caching on all the pages loaded in dynamically.
Browsers would be IE8 onwards.
As you said you should only be doing that if the website is in development or the content really needs to be loaded fresh every time. Internet Explorer supports some meta tags that can do what you need, specifically
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<META HTTP-EQUIV="Expires" CONTENT="-1">
Click here for more information
If you ever want to test in firefox, you could try out this plugin
If you are using Google Chrome to develop, there are an option that let you cache free when dev tools is open, but if you want a simple trick is just to pass a timestamp in a query string during your request. Something like:
http://localhost/path/to/project/?nocache=74567363
If you are using some framework that helps you to handle with the includes like AngularJS ou BackboneJS, make the redirects with:
var myUrl = 'http://localhost/path/to/project/?nocache=';
var timestamp = (new Date()).getTime();
window.location.href = myUrl + timestamp;

Force Internet Explorer to ignore IE=EmulateIE8

I'm working with Blackboard 9.1 SP13 and by the default the platform has the typical:
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE8" />
But i want Internet Explorer >8 to ignore this meta tag in just one page because it is not working properly.
I can't change the meta tag since it is hardcoded in the platform and I can't customize this feature (my boss doesn't allow me to change de .vm template, it is not an option).
¿Is there a way I can tell Internet Explorr >8 to ignore this meta in the page with a code inside the page? Some kind of Javascript or something...
Thanks in advance
Try having the server send the equivalent header with a new value:
X-UA-Compatible: IE=edge
In general, headers from the server override headers set in HTML.

Categories

Resources