I'm currently working on an android app using android studio and the google cloud endpoints module with android studio. So I'm trying to add User authentication through the Firebase Auth so I can provide my users with sign-in options from different users. However whenever I try to add the authentication code to the API in my endpoint class. The apiIssuer and ApiissuerAudience are always unresolved. I've tried everything and I can't fix the issue so I'm assuming I didn't do or did something wrong to affect this part of the code.
package com.example.Kendrickod.myapplication.backend;
import com.example.Kendrickod.myapplication.backend.domain.Profile;
import com.google.api.server.spi.auth.EspAuthenticator;
import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiNamespace;
import com.google.api.server.spi.config.Named;
/**
* Defines event APIs.
*/
/** An endpoint class we are exposing */
#Api(name = "event",
version = "v1",
namespace = #ApiNamespace(ownerDomain =
"backend.myapplication.Kendrickod.example.com",
ownerName = "backend.myapplication.Kendrickod.example.com",
packagePath = ""),
authenticators = {EspAuthenticator.class},
issuers = {
#ApiIssuer(
name = "firebase",
issuer = "https://securetoken.google.com/YOUR-PROJECT-ID",
jwksUri = "https://www.googleapis.com/service_accounts/v1/metadata/x509/securetoken#system.gserviceaccount.com")
},
issuerAudiences = {
#ApiIssuerAudience(name = "firebase", audiences = "YOUR-PROJECT-ID")
},
clientIds = {Constants.WEB_CLIENT_ID, Constants.ANDROID_CLIENT_ID, Constants.IOS_CLIENT_ID},
audiences = {Constants.ANDROID_AUDIENCE})
public class EventApi {
}
You must include this library!
com.google.endpoints:endpoints-framework-auth:1.0.2
it seems trivial but not easy to find out ... I got to try them all.
if you use Android Studio, go to Build / Edit library and dependencies click on the "+" and search for "endpoints-framework"
Related
I am following the EXACT steps indicated here
https://cloud.google.com/translate/docs/glossary#create-glossary
to create a online glossary.
I am getting the following error
madan#cloudshell:~ (focused-pipe-251317)$ ./rungcglossary
{
"error": {
"code": 400,
"message": "Empty resource name.; Resource type: glossary",
"status": "INVALID_ARGUMENT"
}
}
Here is the body of my request.json
{
"languageCodesSet": {
"languageCodes": ["en", "en-GB", "ru", "fr", "pt-BR", "pt-PT", "es"]
},
"inputConfig": {
"gcsSource": {
"inputUri": "gs://focused-pipe-251317-vcm/testgc.csv"
}
}
}
The inputUri path i copied from the google cloud bucket file URI box.
I am not able to understand what the issue is. All I know is something is wrong with the inputUri string.
Please help.
Thanks.
I am a Google Cloud Technical Support Representative and we know that, for the moment, there is an issue with the REST API which is on track. I tried to reproduce your situation and while trying to create the glossary using directly the API I got the same issue as you.
After that, I have tried to create the glossary programmatically using a HTTP Triggered Python Cloud Function and everything went just right. In this manner your API will be called with the Cloud Functions service account.
I will attach the code of my Python Cloud function:
from google.cloud import translate_v3beta1 as translate
def create_glossary(request):
request_json = request.get_json()
client = translate.TranslationServiceClient()
## Set your project name
project_id = 'your-project-id'
## Set your wished glossary-id
glossary_id = 'your-glossary-id'
## Set your location
location = 'your-location' # The location of the glossary
name = client.glossary_path(
project_id,
location,
glossary_id)
language_codes_set = translate.types.Glossary.LanguageCodesSet(
language_codes=['en', 'es'])
## SET YOUR BUCKET URI
gcs_source = translate.types.GcsSource(
input_uri='your-gcs-source-uri')
input_config = translate.types.GlossaryInputConfig(
gcs_source=gcs_source)
glossary = translate.types.Glossary(
name=name,
language_codes_set=language_codes_set,
input_config=input_config)
parent = client.location_path(project_id, location)
operation = client.create_glossary(parent=parent, glossary=glossary)
result = operation.result(timeout=90)
print('Created: {}'.format(result.name))
print('Input Uri: {}'.format(result.input_config.gcs_source.input_uri))
The requirements.txt should include the following dependencies:
google-cloud-translate==1.4.0
google-cloud-storage==1.14.0
Do not forget to modify the code with your parameters
Basically, I have just followed the same tutorial as you, but for Python and I used Cloud Functions. My guess is that you can use App Engine Standard, as well.This may be an issue regarding the service account that are used to call this API. In case this doesn´t work for you let me know and I will try to edit my comment.
I am trying to figure out how to update a colums in a Dynamo table, using the 'aws-amplify' API.
Without Amplify, (just using the AWS SDK), that could be done like this:
const docClient = new AWS.DynamoDB.DocumentClient();
let params = {
TableName:table,
Key:{
"year": year,
"title": title
},
UpdateExpression: "set info.rating = :r, info.plot=:p, info.actors=:a",
ExpressionAttributeValues:{
":r":5.5,
":p":"Everything happens all at once.",
":a":["Larry", "Moe", "Curly"]
},
ReturnValues:"UPDATED_NEW"
};
docClient.update(params, function(err, data) { ....
I set up a backend/api using the docs here to ( enable cloud API to do CRUD operations)
https://docs.aws.amazon.com/aws-mobile/latest/developerguide/web-access-databases.html
Everything works fine as far as 'put/get' methods that create new records,etc
import Amplify, { API } from 'aws-amplify';
....
const path = '/MyTable';
const newRecord = {.......}
const apiResponse = await API.put('MyTableCRUD', path, newRecord);
But there is so little documentation on more advanced techniques like the update above, that I don't know how if/how this can be achieved using Amplify.
Hoping someone has already done this!
Thank you
You can create a custom route in the cloud API of your database (which is usually located under awsmobilejs/backend/cloud-api/INSERT_TABLE_NAME). Unless you modified the cloud API of your database in the past, the main file where all of the routes of the API are specified should be awsmobilejs/backend/cloud-api/INSERT_TABLE_NAME/app.js, or in your case awsmobilejs/backend/cloud-api/MyTable/app.js.
For more information about creating custom routes in your cloud API and some examples, check out the example app's cloud API and the express API reference.
I am migrating an addon from mozilla. (Migrating from ADDONS-SDK to WebExtensions technology, however I'm encountering problems when importing the main API classes.
When the plugin was made with ADDON-SDK, the import was done like this:
// Import the main SDK libs to use in the project
var data = require ("sdk / self").
var pageMod = require ("sdk / page-mod");
var utils = require ('sdk / window / utils');
const {Cc, Ci, Cu} = require ("chrome");
const Ac = console;
// Loading services
const OS = Cc ['# mozilla.org/observer-service;1'].getService(Ci.nsIObserverService);
const LOADER = Cc ['# mozilla.org/moz/jssubscript-loader;1'].getService(Ci.mozIJSSubScriptLoader);
const IOS = Cc ["# mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
// import browser configuration files
Cu.import ("resource: //gre/modules/Services.jsm");
// Loading other project files
LOADER.loadSubScript ('chrome: //vigiamcviewer/content/HTTP.js');
However, in WebExtensions, I did not find anything like doing the imports.
I've browsed the API and found a good example of the SDK, but nothing like how to do the same with WebExtensions.
I am new to dart and I have been trying to figure out how to use the googleapis library to update a calendars events, then display the calendar/events on a webpage.
So far I have this code that I was hoping would just change the #text id's text to a list of events from the selected calendars ID:
import 'dart:html';
import 'package:googleapis/calendar/v3.dart';
import 'package:googleapis_auth/auth_io.dart';
final _credentials = new ServiceAccountCredentials.fromJson(r'''
{
"private_key_id": "myprivatekeyid",
"private_key": "myprivatekey",
"client_email": "myclientemail",
"client_id": "myclientid",
"type": "service_account"
}
''');
const _SCOPES = const [CalendarApi.CalendarScope];
void main() {
clientViaServiceAccount(_credentials, _SCOPES).then((http_client) {
var calendar = new CalendarApi(http_client);
String adminPanelCalendarId = 'mycalendarID';
var event = calendar.events;
var events = event.list(adminPanelCalendarId);
events.then((showEvents) {
querySelector("#text2").text = showEvents.toString();
});
});
}
But nothing displays on the webpage. I think I am misunderstanding how to use client-side and server-side code in dart... Do I break up the file into multiple files? How would I go about updating a calendar and displaying it on a web page with dart?
I'm familiar with the browser package, but this is the first time I have written anything with server-side libraries(googleapis uses dart:io so I assume it's server-side? I cannot run the code in dartium).
If anybody could point me in the right direction, or provide an example as to how this could be accomplished, I would really appreciate it!
What you might be looking for is the hybrid flow. This produces two items
access credentials (for client side API access)
authorization code (for server side API access using the user credentials)
From the documentation:
Use case: A web application might want to get consent for accessing data on behalf of a user. The client part is a dynamic webapp which wants to open a popup which asks the user for consent. The webapp might want to use the credentials to make API calls, but the server may want to have offline access to user data as well.
The page Google+ Sign-In for server-side apps describes how this flow works.
Using the following code you can display the events of a calendar associated with the logged account. In this example i used createImplicitBrowserFlow ( see the documentation at https://pub.dartlang.org/packages/googleapis_auth ) with id and key from Google Cloud Console Project.
import 'dart:html';
import 'package:googleapis/calendar/v3.dart';
import 'package:googleapis_auth/auth_browser.dart' as auth;
var id = new auth.ClientId("<yourID>", "<yourKey>");
var scopes = [CalendarApi.CalendarScope];
void main() {
auth.createImplicitBrowserFlow(id, scopes).then((auth.BrowserOAuth2Flow flow) {
flow.clientViaUserConsent().then((auth.AuthClient client) {
var calendar = new CalendarApi(client);
String adminPanelCalendarId = 'primary';
var event = calendar.events;
var events = event.list(adminPanelCalendarId);
events.then((showEvents) {
showEvents.items.forEach((Event ev) { print(ev.summary); });
querySelector("#text2").text = showEvents.toString();
});
client.close();
flow.close();
});
});
}
I'm starting a mini blog for my honeymoon with Google App Engine, Flask and Stripe that we can send to family and friends. Everythings working great, except for Stripe.
Error Received:
File "/Users/MDev/Desktop/Steph_Max/Wedding/main.py", line 131, in charge
customer = stripe.Customer.create(
AttributeError: 'function' object has no attribute 'Customer'
This is the code line it's referring to in the error.
#app.route('/stripe')
def stripe():
return render_template('stripe.html', key=stripe_keys['publishable_key'])
#app.route('/charge', methods=['POST'])
def charge():
# Amount in cents
amount = 500
customer = stripe.Customer.create(
email = 'customer#example.com',
card = request.form['stripeToken']
)
charge = stripe.Charge.create(
customer=customer.id,
amount=amount,
currency='usd',
description='Flask Charge'
)
return render_template('charge.html', amount=amount)
I have my main.py setup with just the default checkout as documented in Stripe docs:
from flask import Flask
from flask import render_template, request, redirect, url_for
from werkzeug.utils import secure_filename
from flask import send_from_directory
import stripe
import os
app = Flask(__name__)
#app.config['DEBUG'] = True
stripe_keys = {
'secret_key' : os.environ['SECRET_KEY'],
'publishable_key' : os.environ['PUBLISHABLE_KEY']
}
stripe.api_key = stripe_keys['secret_key']
My index page works (I've renamed it stripe.html) but the issue is just when it goes to the charge page. The script for the stripe button is working, I can submit a fake card, everything works except unto the charge page.
I'm on the noob side of noob so please be patient with me and if I'm missing something I'll update ASAP :)
Versions:
stripe: stripe-1.14.0-py2.7.egg-info
Python: 2.7
GAE: 1.9.3
The problem is you have imported the stripe library and then defined a function with the same name.