How do you access Facebook scope data with Firebase Auth - firebase

I'm trying to access data requested from Facebook. Here is my code:
var auth_provider_facebook = new firebase.auth.FacebookAuthProvider();
/// BEGIN: configure the facebook authorization provider.
auth_provider_facebook.addScope('user_birthday');
auth_provider_facebook.addScope('user_about_me');
auth_provider_facebook.addScope('user_work_history');
auth_provider_facebook.addScope('user_education_history');
// auth_provider_facebook.addScope('user_birthday,user_about_me,user_work_history,user_education_history');
/// END: configure the facebook authorization provider.
I've tried one-lining it and multi-lining it, but I am still having trouble getting the data. The documentation found here has absolutely no information on retrieving data from the scope. The documentation provided here mentions a facebook variable as part of the result, but it's always undefined. There's more documentation here that brings up a thirdPartyUserData property which is also always undefined.
How do I go about obtaining this data?

When you authenticate, onAuthStateChange will give you a token. This is mine with multiple account linked.
Can you find it? Are you using Firebase v3?

Related

React Native Firebase returns [auth/account-exists-with-different-credential ]

I currenlty have multiple login methods like facebook,twitter and google. If i login from facebook and then login back from twitter , it will throw me an error [auth/account-exists-with-different-credential ]. What i want to do is link all the accounts.
Some answers says, there is error.email and error.credential on [auth/account-exists-with-different-credential ] this kind of error. But there is not.
if (error.code === 'auth/account-exists-with-different-credential') {
// todo
}
What should i do in todo section to link the providers.
I think I found the cause of the error.
The error response might be different per package.
If you are using the mobile based package of firebase(#react-native-firebase/app)
or the web based variant of firebase(firebase/app).
The mobile firebase package supports more functionality for the phone, but it might only return the error message and error code. In the web based variant it support more properties as the email & credential object.
I am also working on a linking account for multiple auth service providers, whenever I get the errorCode: 'auth/account-exists-with-different-credential'. The drawback of this flow is that you might need to re-login with a different service provider to make the link work. So this can be quite a drag in the login flow.
Here is a discussion link where I received more information about this topic: https://github.com/invertase/react-native-firebase/issues/2802

Google Analytics API (Real-time) in Google Sheets

I'm trying to access the Google Analytics API via Google Sheets (Google Script).
So within the script, I'm trying to use the URI as described here: https://developers.google.com/analytics/devguides/reporting/realtime/v3/reference/data/realtime/get
The API call looks something like this:
GET https://www.googleapis.com/analytics/v3/data/realtime?ids=3254435&metrics=ga%3AActiveUsers&key={YOUR_API_KEY}
Within my Google Analytics Script, I've also created a Public API Access key:
However, I can't seem to get any data whether if I'm appending the token key in the URI or within the header.
Can any one point me to the right direction?
Thanks
The public api key is for public access APIs. Data that is not owned by a user. You need to create client id from web application.
Then you will be able to authenticate it using Oauth2.
this might get you started. https://developers.google.com/apps-script/advanced/analytics
How to know when you need to be authenticated:
Public API: Aanalytics metadata API meta data doesn't belong to any user its public data anyone can access.
User data API: Google Analytics Real-time Data the data returned is owned by a user, it is not public data viewable by everyone. Documentation states
Requires authorization
If the documentation says requires authentication then you have to be authenticated to access that call.
You can use Google Analytics API easily just by enabling them in App Script.
Below is the Guide to using Real-time API in Google Spreadsheet
https://www.tatvic.com/blog/google-analytics-real-time-data-in-google-sheet/
Just like above you can use any API no need to take care of tokens.

Google Oauth flow in Meteor

Within a Meteor app, can anyone guide me to how to allow users to simply Oauth Google?
There's the accounts-google package, but I don't want users to be able to login with it, just oauth and store credentials.
The docs mention "If you just want to authenticate to an Oauth service like Twitter, Facebook, or Google without using Accounts – that is, if you don't want to log the user in, you just want an OAuth token – you can use the underlying service packages such as twitter, facebook, and google directly.", but there are no docs whatsoever for the google package.
Any guidance would be much appreciated.
The Oauth's package is intended to do just this. If you want to use it to get people's credentials
There are two options:
1) Modify the source of the google and accounts-google packages to remove the parts that log you in. There are no docs for this, i'm afraid, the best to understand it are the inline comments.
2) Use another atmosphere package to merge accounts-google with an existing login. So they're already logged in but can use Meteor.logInWithGoogle() to login with google and this is merged with their existing account. This way they don't have to log in with Google but you get to store the OAuth token. For this you can use the bozhao:link-accounts package, or the mikael:accounts-merge package:
// ON THE CLIENT:
Meteor.signInWithGoogle ({}, function (error, mergedUserId) {
// mergedUsers is set if a merge occured
if (mergedUserId) {
console.log(mergedUserId, 'merged with', Meteor.userId());
}
});
Then you would find the google OAuth token data in services.google on your existing Meteor.user() document.
It's fairly straight forward to handle the Google OAuth manually. Check my answer on this (similar) SO question
Getting OAuth tokens without user registration

Accessing Google analytics api using api key

I'm trying to implement Google analytics API using API key to make it available without authorization. But i can get examples using CLIENT ID in google developer console itself. Can anyone help me with an example using api key?
It is not possible to access Google Analytics API with the API key. You must use Open Authentication.
If you are trying to access your own data you can use a service account. Create new credentials choose Service Account.
You can then take the service account email address:
1046123799103-nk421gjc2v8mlr2qnmmqaak04ntb1dbp#developer.gserviceaccount.com
Add it as a user at the ACCOUNT level it is very important that it be at the ACCOUNT level it wont work other wise. Your application with then be able to access your Google Analytics data with out a log in.
Without knowing what language you are working with I cant give you any examples.
Update:
If as you say you are planning on doing this with JavaScript then you will have to go with Oauth2 and request access. There is no way to use a Service account with JavaScript.
There for I strongly recommend that you find a server sided programing language to do this in. Even if it did work with JavaScript you would end up running out of quota on the API before to long.
Google Analytics' EmbedAPI will allow you to display your Google Analytics via javascript, and users will be able to log in on page.
You will still need to get your clientAPI, but then users will be able to login independently.
The javascript code is described in the dev guide and a sample is below:
<script>
gapi.analytics.ready(function() {
// Step 3: Authorize the user.
var CLIENT_ID = 'Insert your client ID here';
gapi.analytics.auth.authorize({
container: 'auth-button',
clientid: CLIENT_ID,
});
</script>
The API limit should be no problem, its 50,000 calls per day.

Google Analytics API: "User does not have sufficient permissions for this account."

I'm writing a Ruby app that accesses the Google Analytics API to pull down some experiment information.
The app connects and authenticates using a Google Service Account via the following function:
def connect
...
##client = Google::APIClient.new(:application_name => 'My Service App',
:application_version => '1.0.0')
key_file = Rails.root.join('config', 'privatekey.p12').to_s
key_secret = 'somesecret'
key = Google::APIClient::PKCS12.load_key(key_file, key_secret)
asserter = Google::APIClient::JWTAsserter.new(
SECRETS[:google_service_account_email],
['https://www.googleapis.com/auth/yt-analytics.readonly',
'https://www.googleapis.com/auth/analytics.readonly'
],
key
)
##client.authorization = asserter.authorize()
...
end
...which authenticates and discovers both APIs without issue.
Using the client against the YouTube Analytics API works without issue. Using the same exact account to access the Analytics API via...
response = ##client.execute({
# 'analytics is the API object retrieved via discover_api()
:api_method => analytics.management.experiments.list,
:parameters => {
'accountId' => 'AAAAAAAA',
'profileId' => 'PPPPPPPP',
'webPropertyId' => 'UA-WWWWWWWW-#'
}
})
Results in a 403 error response:
{"domain":"global","reason":"insufficientPermissions","message":"User does not have sufficient permissions for this account."}
In regards to authorization, I have double-checked the account service#myapp.com:
Has full permissions to the Google Analytics web interface. I logged in using the service#myapp.com account and was able to view the same Experiments I attempted to list.
Has enabled the Analytics API. Within the API Console, I confirmed in the Services section that the Analytics API item is switch to ON. (Just like YouTube Analytics is.)
I am using the appropriate AccountID, ProfileID, and WebPropertyID values. Copied directly from the Google Analytics web interface.
Given that the service account can access at least one API (YouTube Analytics), and the associated account (service#myapp.com) can access the Analytics web interface, there seems to be something wrong with the service account accessing the Analytics API in particular.
Any ideas?
Similar topics:
“Not sufficient permissions” google analytics API service account (NOTE: This error is slightly different than mine)
Analytics blog post, check comments section for 'permissions'
Make sure you give the service account email (something like 1234567890#developer.gserviceaccount.com) permissions to read/write from your GA view.
Admin > View > User Management > "Add permissions for:"
Pick the right id!
In my case I was using the right credentials (account id, account secret -> authorization_code -> access_token) AND had the email permissions set up right but I was using the account id on the Admin > Account settings page and simply adding ga: to the front.
The id you actually need is the table id! (or that's the one that worked for me at least since most people here are mentioning the account id, which didn't work for me.). You can find that one here: https://ga-dev-tools.appspot.com/account-explorer/
And then you can query as
service.get_ga_data(TABLE_ID,'2017-03-25','2017-03-25','ga:users,ga:pageviews')
I found this API to be badly documented overall and the UI was unclear. But maybe that's just me.
If you still see this message after you added your developer email to analytic user.
You may need to add scope to the object, before new Google_Service_Analytics($client);
$client->setScopes("https://www.googleapis.com/auth/plus.login");
I spent whole day trying to solve this!
I also had to go to the developer console and enable the API in order to make it work. Go to the developer console and select your project and enable the API(s) you want to use.
Make sure your are entering the correct table_id
(ie. GetProfiles(oauth_token)
tableid_input = "ga:72848696")
Even after adding the email to the account level in analytics I still had the same permission problem but the following suggestion helped but didn't solve it:
$client->setScopes("https://www.googleapis.com/auth/plus.login");
That didn't work for me but this did:
$client->setScopes("https://www.googleapis.com/auth/analytics");
https:// is now required to authenticate.
If you are new just to let you know 3 Step procedure required
Enable Google Analytics Reporting API then create service email account (OAuth Client ID)
Add and give permission this service email in google console
Add and give permission this service email account in Google analytics tracking -> User management
Make sure you give the service account email (something like 1234567890#developer.gserviceaccount.com) permissions to read/write from your GA view.
Admin > View > User Management > "Add permissions for:"
I got this issue when I try to integrate GA source to metabase.
Metabase requires Oauth clientid and secret. So I create Oauth clientid in GA (If you face an issue which said you need a Guite user to make it internal access, then you need register a new account under workspace).
Then, I solve this issue by adding my google cloud(workspace) account to view user management, not
1234567890#developer.gserviceaccount.com
Just the google cloud login account, I tried with 1234567890#developer.gserviceaccount.com but it doesn't work. The difference for metabase is it ask the oauth id and secret for your google cloud account not service account.
Hope this can help someone face the same situation.
But it is still trick because another GA4 service which don't have any view
How to create view in Google Analytics 4
Still can't solve this issue.
If any one knows it, please comment. Just don't know how to call the api in GA4 since there isn't view at all.
For me, it has been solved when I select the property that was created with enabling "Create a Universal Analytics property" in "Show Advanced Options" section
Other answers are outdated for Google Analytics v4.
There's a different api that one need to enable and use.
https://developers.google.com/analytics/devguides/reporting/data/v1/quickstart-client-libraries
For node.js:
import { BetaAnalyticsDataClient } from "#google-analytics/data";
import { google } from "googleapis";
const auth = new google.auth.GoogleAuth({
credentials: {
client_email: process.env.GOOGLE_CLIENT_EMAIL,
client_id: process.env.GOOGLE_CLIENT_ID,
private_key: process.env.GOOGLE_PRIVATE_KEY,
},
});
const analyticsDataClient = new BetaAnalyticsDataClient({
auth,
});
If someone has more view he should use the view ID.

Resources