I want to consume AWS product advertising API, I stuck with generating Signature.
Can someone please post the code snippet for creating signature using Javascript.
I had the same issue until last hour ago. After googling many links. Finally i found solution for it.
My solution is here
var Message = "GET" + "\n" + "elasticmapreduce.amazonaws.com" +"\n"+ "AWSAccessKeyId=AKIAIOSFODNN7EXAMPLE&Action=DescribeJobFlows&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2011-10-03T15%3A19%3A30&Version=2009-03-31";
var secret = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
var hash = CryptoJS.HmacSHA256(Message, secret);
document.write(hash);
document.write("|| and ||");
var hashInBase64 = CryptoJS.enc.Base64.stringify(hash);
document.write(hashInBase64);
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/rollups/hmac-sha256.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/3.1.2/components/enc-base64.js"></script>
You can verify your signature from https://mws.amazonservices.com/scratchpad/index.html
But beaware of timestamp. Signature vary depends on timestamp
Related
Recently, I'm working on AWS Amplify, Which has java and javaScripts related example, but no .net related example. after next i solved this below the way. Here is my question this is the only process to request or response, another way that i missed.
const string query = "query ";
var serializer = new NewtonsoftJsonSerializer();
using var graphQlClient = new GraphQLHttpClient("https://xx.xx.xx.amazonaws.com/graphql", serializer);
graphQlClient.HttpClient.DefaultRequestHeaders.Add("x-api-key", "<api key>");
var subscriptionStream = await graphQlClient.SendQueryAsync<dynamic>(query);
I expect a better way, except my current code.
I was working on something that would modify my promotional sms messages. I read that it is possible via CampaignHook in Pinpoint. But from the documentation, I couldn't gather how this will actually work. I have followed it until adding permission and linking the pinpoint app id and with it. I have followed this link: https://github.com/Ryanjlowe/lambda-powered-pinpoint-templates
For some reason, I am not able to follow what I need to do on the Lambda (boto3) function side to try and make this work. Is there an example code (python) or well-documented example for this? It would help me a lot. Thanks!
The Pinpoint developer guide describes how to setup a CampaignHook under the chapter "Customizing segments with AWS Lambda".
https://docs.aws.amazon.com/pinpoint/latest/developerguide/segments-dynamic.html
"To assign a Lambda function to a campaign, you define the campaign's CampaignHook settings by using the Campaign resource in the Amazon Pinpoint API. These settings include the Lambda function name. They also include the CampaignHook mode, which specifies whether Amazon Pinpoint receives a return value from the function."
The docs show an example Lambda function:
'use strict';
exports.handler = (event, context, callback) => {
for (var key in event.Endpoints) {
if (event.Endpoints.hasOwnProperty(key)) {
var endpoint = event.Endpoints[key];
var attr = endpoint.Attributes;
if (!attr) {
attr = {};
endpoint.Attributes = attr;
}
attr["CreditScore"] = [ Math.floor(Math.random() * 200) + 650];
}
}
console.log("Received event:", JSON.stringify(event, null, 2));
callback(null, event.Endpoints);
};
"In this example, the handler iterates through each endpoint in the event.Endpoints object, and it adds a new attribute, CreditScore, to the endpoint. The value of the CreditScore attribute is simply a random number."
I would like to connect to the Facebook Ads Insights API with google scripts in order to generate and update a google sheet containing my ads key performance indicators.
I have read Facebook's documentation but I'm a bit lost, for example In the documentation's website, I can see that I am supposed to follow this syntax to get a campaign's impressions
GET <AD_OBJECT>/insights?fields=impressions
but I'm not quite sure where that would fit in a cURL get query, should it look like this ?
https://graph.facebook.com/v2.5/CAMPAIN_ID/insights?fields=impressions%?access_token=TOKEN
I have tried to build the following google script but I'm not sure it's getting anywhere, any help ?
var myClientID = '';
var myClientSecret = '';
var myAccessToken = 'MY_TOKEN';
var graphURL = 'https://graph.facebook.com/v2.5/';
function getPageLikes(campaign_id) {
var searchParams = '?fields=impressions%2Cunique_clicks%2Creach';
var campaignID = MY_CAMPAIGN_ID;
var fullURL = graphURL + campaignID + '/insights/' + searchParams + '&access_token=' + myAccessToken;
var fetchResult = UrlFetchApp.fetch(fullURL);
var campaign = JSON.parse(fetchResult);
var likes = campaign.data[0];
return campaign_data;
}
Thank you
Yes. If you like CURL, you should play with https://developers.facebook.com/tools/explorer/
Then you can formulate something like:
https://graph.facebook.com/v2.9/[campaign_id]/insights?fields=impressions%2Creach&access_token=[token]
But if you want an easier life, I would recommend you to use one of the SDK. There is one for
PHP: https://github.com/facebook/facebook-php-ads-sdk
Python: https://github.com/facebook/facebook-python-ads-sdk
Java: https://github.com/facebook/facebook-java-ads-sdk
And we also have a tool to guide you generate code in the Getting Started session in https://developers.facebook.com/apps/[app_id]/marketing-api/
Basically you can pick metrics and the wizard will generate a working code for you. (It is only generating Java code for now)
Also if you don't really wants to code, you may try the new product we just released called Facebook Ads Manager for Excel. It allows you to download Insights data into Excel directly. More info:
https://www.facebook.com/business/m/facebook-ads-manager-for-excel
I'm writing a script for Google Sheets that uses Facebook's Graph API to get my data. Everything worked earlier today but suddenly I'm getting an error:
UrlFetch failed because too much traffic is being sent to the
specified URL.
I haven't hit any quotas about using UrlFetch because I can still fetch from other urls that are not graph.facebook.com - so the issue appears to be specifically with Facebook.
Script Code
var myClientID = '';
var myClientSecret = '';
var myAccessToken = '';
var graphURL = 'https://graph.facebook.com/v2.3/';
function getPageLikes(campaign_id) {
var searchParams = '/stats?fields=actions';
var campaignID = campaign_id;
var fullURL = graphURL + campaignID + searchParams + '&access_token=' + myAccessToken;
var fetchResult = UrlFetchApp.fetch(fullURL);
var campaign = JSON.parse(fetchResult);
var likes = campaign.data[0].actions.like;
return likes;
}
Google Sheet Formula
=getWebClicks('E2')
I discovered a solution after a little more research. I added the 'useIntranet' option as a parameter to fetchResult and that seemed to solve the issue. I imagine the request is now being sent from another resource that doesn't limit requests to Facebook's Graph API.
If anyone can explain why this fixed my problem, that would be great as well!
var options = {"useIntranet" : true};
var fetchResult = UrlFetchApp.fetch(fullURL, options);
I don't have Facebook so I can't try this, replace var fetchResult = UrlFetchApp.fetch(fullURL); with:
do{
var fetchResult = UrlFetchApp.fetch(fullURL);
}while(fetchResult == 'UrlFetch failed because too much traffic is being sent to the specified URL.');
Or anything that matches this error object.
The correct answer is: just wait until the ban gets lifted.
I have universal analytics installed on my website, and want to parse the __utmz cookie to get referral info. However, I never see this cookie set.
Has something changed? Any reason this isn't set?
I do see the _ga cookie when I browse my site, and I see the __utmz cookie in my browser cache if I go to other sites.
I checked out the docs, and don't see any reference to this changing recently, so a bit stumped.
Universal Analytics doesn't create any __utm* cookies.
However, you can use Universal Analytics code (analytics.js) AND the traditional code (ga.js) simultaneously on your site. This will allow you to populate your UA profile and scrape the values from __utmz.
It seems like with Universal Analytics, this cookie has disappeared, and you only get a single _ga cookie.
Source: https://developers.google.com/analytics/devguides/collection/analyticsjs/cookie-usage
Also mentioned here: How to get the referrer, paid/natural and keywords for the current visitor in PHP with new Google Analytics?
Also given that analytics is primarily a tool to collect aggregated information, I couldn't find (and I doubt) that there is any way to query GA to get this info back, given the _ga cookie.
You can create your own cookie and store the query string parameters that google analytics use (utm_campaign and etc).
See this project as example:
https://github.com/dm-guy/utm-alternative
Use below code to get utmz cookie along with your universal analytics js code
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXX-X']);
(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>