I've spent an embarrassingly long time on this seemingly incredibly easy problem with 0 progress. I'm pretty desperate at this point, so if anybody could review the short example I've written, I would greatly appreciate it.
What I'm trying to do: send a push notification using OneSignal's Web Push SDK.
Files in ~/Desktop/OneSignal-Browser-Example:
index.html
<head>
<title>OneSignal Example</title>
<link rel="manifest" href="/manifest.json">
<script src="https://cdn.onesignal.com/sdks/OneSignalSDK.js" async></script>
<script>
var OneSignal = window.OneSignal || [];
OneSignal.push(["init", {
appId: "518e60ef-8b73-4852-8172-61cb170dce00",
autoRegister: true,
notifyButton: {
enable: true /* Set to false to hide */
}
}]);
console.log("Test");
</script>
<h1>LOADED</h1>
</head>
manifest.json
{
"name": "OneSignal Example",
"short_name": "OneSignalExample",
"start_url": "/",
"display": "standalone",
"gcm_sender_id": "482941778795"
}
OneSignalSDKWorker.js
importScripts('https://cdn.onesignal.com/sdks/OneSignalSDK.js');
OneSignalSDKUpdaterWorker.js
importScripts('https://cdn.onesignal.com/sdks/OneSignalSDK.js');
cert.pem
key.pem
I launched Google Chrome with /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --ignore-certificate-errors, and set up a https server on port 8081 with http-server --ssl --p 8081 ~/Desktop/OneSignal-Browser-Example.
Attached is a screenshot of the trace log.
I think we were able to help you out over our support channel to solve the issue.
The issue was a specific configuration mismatch: uPaymeiFixit had modified the manifest.json file's gcm_sender_id property to an incorrect value; he subscribed after this change and registered his user with a mismatched GCM Sender ID which prevented notifications from being able to send even though everything else was correct.
The solution to this issue was to:
Correct the gcm_sender_id value.
Reset his site data and cache to test again as a new user.
He was able to receive a notification right after these changes.
Related
I am using a commenting system called isso.
https://posativ.org/isso/
<script
data-isso="{{url}}/"
data-isso-require-author="true"
data-isso-require-email="true"
data-isso-css="true"
data-isso-reply-to-self="true"
data-isso-vote="true"
data-isso-vote-levels="[-5,5,15]"
src="{{ url}}/js/embed.min.js">
</script>
I have set data-isso-vote="true"
However I get the below message,
{"likes": 0, "dislikes": 0, "message": "Upvote denied because a vote has already been registered for this remote address:IP"}
Any idea on what I may be missing?
If you are forwarding the incoming requests to in instance of isso running at localhost, it might be necessary to set the trusted-proxies in the isso.conf file, or else all the votes would appear to come from the same IP. I guess that could be the issue here.
I'm trying to put a QR barcode scanner in my website using Quagga after lots of trying I finally succeeded to put the live reader, its ask for permission to use in the pc but when I'm trying to access it through my phone it doesn't work, and by doesn't work I mean doesn't even ask for permission to open the camera
I am rendering the script tag on the ejs file and it looks something like this:
<script src="js/quagga.min.js"></script>
<script>
Quagga.init({
inputStream : {
name : "Live",
type : "LiveStream",
target: document.querySelector('#camera')
},
decoder : {
readers : ["code_128_reader"]
}
}, function(err) {
if (err) {
console.log(err);
return
}
console.log("Initialization finished. Ready to start");
Quagga.start();
});
Quagga.onDetected(function(data){
document.body.appendChild("<h1>"+data.codeResult.code +"</h1>")
});
</script>
Thanks in advance!
SOLVED!
for the chrome version that is 47+, it seems like you don't have permission to use the camera on unsecure website, and mine was on the localhost.
so I got into the chrome flags and inside of that I searched "Insecure origin treated as secure" and then I added my laptop IP and the opened port and it worked!
the "Yahha Udin" question answered by "Kartik Sharma" (link below) helped me solve it.
link: "unsafely-treat-insecure-origin-as-secure" flag is not working on Chrome
I'm receiving this error from Google API Oauth:
idpiframe_initialization_failed", details: "Not a valid origin for the client: http://127.0.0.…itelist this origin for your project's client ID
I'm trying to send a request from this local path:
http://127.0.0.1:8887/
And I already added this URL to the Authorized JavaScript origins
section:
This is my code:
<!-- The top of file index.html -->
<html itemscope itemtype="http://schema.org/Article">
<head>
<!-- BEGIN Pre-requisites -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js">
</script>
<script src="https://apis.google.com/js/client:platform.js?onload=start" async defer>
</script>
<!-- END Pre-requisites -->
<!-- Continuing the <head> section -->
<script>
function start() {
gapi.load('auth2', function() {
auth2 = gapi.auth2.init({
client_id: 'MY CLIENT ID.apps.googleusercontent.com',
// Scopes to request in addition to 'profile' and 'email'
//scope: 'https://www.google.com/m8/feeds/'
});
});
}
</script>
</head>
<body>
<button id="signinButton">Sign in with Google</button>
<script>
$('#signinButton').click(function() {
// signInCallback defined in step 6.
auth2.grantOfflineAccess().then(signInCallback);
});
</script>
<!-- Last part of BODY element in file index.html -->
<script>
function signInCallback(authResult) {
if (authResult['code']) {
// Hide the sign-in button now that the user is authorized, for example:
$('#signinButton').attr('style', 'display: none');
// Send the code to the server
$.ajax({
type: 'POST',
url: 'http://example.com/storeauthcode',
// Always include an `X-Requested-With` header in every AJAX request,
// to protect against CSRF attacks.
headers: {
'X-Requested-With': 'XMLHttpRequest'
},
contentType: 'application/octet-stream; charset=utf-8',
success: function(result) {
// Handle or verify the server response.
},
processData: false,
data: authResult['code']
});
} else {
// There was an error.
}
}
</script>
<!-- ... -->
</body>
</html>
How can I fix this?
Reseting Chrome cached solved it for me. Long press on Reload button, then Empty Cache and Hard Reload.
Note: Make sure your Chrome Dev tools panel is open otherwise long press wont work.
I had a very similar issue to yours. I tried to add multiple whitelisted ports from localhost and nothing was working. Ended up deleting the credentials and setting them up again. Must have been a bug on googles end for my setup.
If it's all the same to you, try adding http://localhost:8887 to your authorized JavaScript origins instead. Had that error myself at some point and this fixed it. Know that you will have to use this URL for your request as well event though it translates to http://127.0.0.1:8887/.
I read on several places on the web people use to redo the creation of the credentials to get it to work.
So I did, I created a new credential for the same project and used my new user-id and it worked perfectly... Looks like the edition of the whitelist is a bit flacky...
Nb: I also used localhost instead of 127.0.0.1, IPs are not valid.
I fiddled around for about 10 minutes and then it finally worked when I tried
http://localhost/ in the browser (instead of 127.0.0.1)
Added the url at every place you can do white-lists at:
https://console.developers.google.com/apis/credentials/
I had this same issue; but this is what worked for me:
Open console.developers
Open the project name
Click on the credentials
Under the "name", click on the "web client 1"
Under the "URLs", add "http://localhost:3000"
just my 2 cents.. was able to get it working after deleting and recreating the credentials. Just as suggested above.
In case anyone missed this, next to the save button it does say:
Note: It may take 5 minutes to a few hours for settings to take effect
Waiting fixed this issue for me.
"Not a valid origin for the client" seems to be over-used by Google's API, i.e. it's misleadingly used for authentication errors too.
For people seeing the error, check that the credentials are correct.
(This might explain why it works for some people after re-creating credentials - in some cases, the original credentials might not have been correct).
I solved via adding both http://localhost and http://localhost:8083.
Okay so this is super embarrasing, but for me I was following the docs for the Google Sign-in Web package for a Flutter app, and where it says:
On your web/index.html file, add the following meta tag, somewhere in the head of the document: <meta name="google-signin-client_id" content="YOUR_GOOGLE_SIGN_IN_OAUTH_CLIENT_ID.apps.googleusercontent.com">
I had copied what was listed as my Client ID and pasted it at the beginning and had therefor duplicated the apps.googleusercontent.com portion of the content label in the meta tag. So it might help to make sure you haven't duplicated that!
I just went through all of these solutions before realizing I was putting in
https://localhost:3000
and my dev server was serving up
http://localhost:3000
Stupid, I know, but someone else will probably make the same mistake and perhaps this comment will help them :)
What worked for us was adding a non-localhost domain to the authorized origins. My colleague had his localhost-domains working after adding a non-existing local domain, e.g. http://test-my-app.local.
It might be in case, while you are using same email id for creating client id and for sign-in through webpage
I am a "newbie" to the Google Analytics API and I am trying to get the "Hello Analytics" example working.
I followed their steps
to create the test web page but I got no results.
When I go to my web page, I see the title, the "Sign in" button and the text area below where the result should appear. When I press "Sign in", that seems to work; the button changes to say "Signed In". However, no results appear.
I am using FireFox so I right-clicked on the text area and selected "Inspect Element"; this shows this error message:
Object { result: Object, body: "{ "error": { "code": 403, …",
headers: Object, status: 403, statusText: "Forbidden" }
I think this is a permission error but do not know how to correct it.
Here is my file HelloAnalytics.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Hello Analytics Reporting API V4</title>
<meta name="google-signin-client_id" content="959582115031-ardmn5vsir7kbcp0dme4d4n1p45bd649.apps.googleusercontent.com">
<meta name="google-signin-scope" content="https://www.googleapis.com/auth/analytics.readonly">
</head>
<body>
<h1>Hello Analytics Reporting API V4</h1>
<p>
<!-- The Sign-in button. This will run `queryReports()` on success. -->
<div class="g-signin2" data-onsuccess="queryReports"></div>
</p>
<!-- The API response will be printed here. -->
<textarea cols="80" rows="20" id="query-output"></textarea>
<script>
// Replace with your view ID.
var VIEW_ID = '92320289';
// Query the API and print the results to the page.
function queryReports() {
gapi.client.request({
path: '/v4/reports:batchGet',
root: 'https://analyticsreporting.googleapis.com/',
method: 'POST',
body: {
reportRequests: [
{
viewId: VIEW_ID,
dateRanges: [
{
startDate: '7daysAgo',
endDate: 'today'
}
],
metrics: [
{
expression: 'ga:sessions'
}
]
}
]
}
}).then(displayResults, console.error.bind(console));
}
function displayResults(response) {
var formattedJson = JSON.stringify(response.result, null, 2);
document.getElementById('query-output').value = formattedJson;
}
</script>
<!-- Load the JavaScript API client and Sign-in library. -->
<script src="https://apis.google.com/js/client:platform.js"></script>
</body>
</html>
I need to understand how to use the Google Analytics API to do simple queries.
FINALLY got it to work!
I was trying to use the API to get data for the Google sample site ("Google Merchandise Store"). I was trying to think of possible reasons for the permission error, and it occurred to me that maybe Google didn't allow Analytics API calls for that web site.
So I went through the effort of setting up my own test web site with Google's Javascript tracking code in it, then defining a new project, enabling the API for it, creating credentials (a client ID) and getting the view ID for my web site. With the new client ID and view ID in my HelloAnalytics.html page, it worked perfectly.
So my guess was correct: Google does NOT permit API calls to get data for its "Google Merchandise Store" sample website. They REALLY should mention this on their "quickstart" page because a "newbie" (like me) wouldn't know that!
I thought I should post my solution because I'm sure that somebody else will run into this problem in the future.
FYI- I have HelloAnalytics.html running on a web server. I am using free web space provided by my ISP.
I created an extension that uses native messaging to a host.
The manifest.json of the extension is:
{
"manifest_version": 2,
"version": "1.0",
"name": "Native Messaging Example",
"description": "Send a message to a native application",
"permissions": [
"nativeMessaging"
],
"browser_action": {
"default_popup": "popup.html"
}
}
The popup.html:
<html>
<head>
<script src="./main.js"></script>
</head>
<body>
<button id="buttonToPress">Press</button>
</body>
</html>
The main.js file:
var port = null;
function connect() {
port = chrome.runtime.connectNative('com.google.chrome.example.echo');
port.onMessage.addListener(function(message) {
alert(message);
port.disconnect();
});
port.onDisconnect.addListener(function() {
port = null;
alert(chrome.runtime.lastError.message);
});
var message = {
'filePath': 'C:\\Users\\username\\Desktop\\themes\\Wallpaper\\Architecture\\img13.jpg'
};
port.postMessage(message);
}
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('buttonToPress').addEventListener('click', connect);
});
I have a native application abc.exe.
The native application manifest.json:
{
"name": "com.google.chrome.example.echo",
"description": "Chrome Native Messaging API Example Host",
"path": "./abc.exe",
"type": "stdio",
"allowed_origins": [
"chrome-extensions://fegpbklgdffjmfjmhknpmgepbddbcghk/"
]
}
In the registrey, The Default Value of HKEY_CURRENT_USER\Software\Google\Chrome\NativeMessagingHosts\com.google.chrome.example.echo is C:\Users\username\Desktop\Extension1\NativeApp\manifest.json (This is where the manifest file is physically exists).
The problem is, that each time i run it, it keep saying: 'Specified Native Messaging Host Not Found'... I rechecked my code and it seems to be fine, just like the google's guide of native messaging. The error that logged in the debugger's console is: 'Uncaught Error: Attempting to use a disconnected port object', which i don't know why it keeps happening.
Also, after the chrome.runtime.connectNative, the .exe doesn't start (after seeing in the task manager), and it just seems likes there something that not code-related, but more likely to be in the configuration.
I need some help in figuring it out, so any help would be usefull!
Thanks
notice that chrome extension listed in allowed_origins has to end with /
wrong code (without /):
"allowed_origins": [
"chrome-extension://acajlpgjiolkocfooiankmegidcifefo"
]
correct code:
"allowed_origins": [
"chrome-extension://acajlpgjiolkocfooiankmegidcifefo/"
]
I've managed to work the solution out. I've created the whole pack once again from scratch and set the name of the host application in lowercase. Also i set the key in the registry in 'CURRENT_USER' and it worked well. I guess that maybe the host name should be in lowercase but other than this I don't know where I went wrong. Thanks alot guys for the help!!! I Appreciate it!
I'm not sure relative paths work for Native Host manifests.
In any case, if you compare with the example in the docs, you're using the wrong kind of slash.