i'm making an app for my school that collects specific data from firebase real-time database, I am currently following a tutorial (i am really new into google apps script). I tried this code:
function getAllData() {
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1g1AELHBONzjEvfMekn3U86xVs9bDdX68bp5i3U2qnjsc)
var firebaseUrl = "https://example.firebaseio.com/";
var base = FirebaseApp.getDatabaseByUrl(firebaseUrl);
var data = base.getData();
for(var i in data) {
Logger.log(data[i].logbookId + ' ' + data[i].logbookfullName + ' ' + data[i].logbookEmail + ' ' + data[i].logbookSubject + ' ' + data[i].logbookDate + ' ' + data[i].logbookTime);
}
}
but it seems It doesn't work. Can someone give me a solution?
There is no native FirebaseApp within Google Script. I believe you are trying to use this Firebase Libray by RomainVialard. First you should follow the Install Guide to install the library into your script.
Add the library key MYeP8ZEEt1ylVDxS7uyg9plDOcoke7-2l into Resources menu > Libraries.
You should then be able to use the FirebaseApp object and functions.
Related
We want to display all leaderboard data into our custom created UI for the game. for that we want to access top scores info such as Profile Picture,Score and Name of the player.
All data will be shown in our custom created UI
we are using following unity3d plugin of google
https://github.com/playgameservices/play-games-plugin-for-unity
Please let us know how to access all players data of our game leaderboard
The you link provided has the actual documentation on how to use the plugin. From Accessing Leaderboard data (where you could get the Score) to Getting Player names, where it is mentioned that you could
use Social.LoadUsers() to load the player profile
from there you could get an IUserProfile to get the image and username. Sample from the same link:
internal void LoadUsersAndDisplay(ILeaderboard lb)
{
// get the user ids
List<string> userIds = new List<string>();
foreach(IScore score in lb.scores) {
userIds.Add(score.userID);
}
// load the profiles and display (or in this case, log)
Social.LoadUsers(userIds.ToArray(), (users) =>
{
string status = "Leaderboard loading: " + lb.title + " count = " +
lb.scores.Length;
foreach(IScore score in lb.scores) {
IUserProfile user = FindUser(users, score.userID);
status += "\n" + score.formattedValue + " by " +
(string)(
(user != null) ? user.userName : "**unk_" + score.userID + "**");
}
Debug.log(status);
});
}
With all that said, if you were hoping for a more detailed and precise sample, it'd be considered as too broad here in Stack Overflow and may be voted to be closed.
I have a huge problem with my ionic app.
When the user clicks on a point of interest, for example train stations and clicks on "open in Google Maps" The App opens the link fullscreen in the app and you have to kill the app, since there is no close button. The Softkeys don't work.
See here:
I guess I have to use the inappbrowser, but how can I enable it inside the map? Deactivating the POI's isn't an option.
Any help much appreciated!
In my case i had in controller.js:
'<a onclick="goto('+obj1[j].places.items[0][0]+','+obj1[j].places.items[0][1]+')">Open in google maps!</a>'
and then in function goto:
window.goto = function(lat,lon){
window.open("https://www.google.com/maps/dir//"+lat+","+lon+"/#",'_system', 'location=yes');
}
Edit:
(....your code....)
var popupContent1 = '<div id="locationContent1">' +
'<div> ' + item.storeName + '</div>' +
'<div> ' + item.address + '</div>' +
'<div> ' + item.city + '</div>' +
'<div>' +'<a onclick="goto('+item.latitude+','+item.longitude+')">Open in google maps!</a>'+ '</div>' +
'</div>';
createInfoWindow(marker, popupContent1);
//marker.bindTo('map',cat.data('goo'),'map');
var infoWindow = new google.maps.InfoWindow();
function createInfoWindow(marker, popupContent1) {
google.maps.event.addListener(marker,'click',function(){ infowindow.setContent(popupContent1);
infowindow.open(map,this);
})
}
i have a question to Google Fit.
I am creating a step counter (oh wonder g). This i have already done so far and it not really hard.
But now we come to my problem. I am only reading the steps with the Sensor API. The issue is, i can add new data via for example the Google Fit app and it will be counted in my app too. This introduces cheating and i do not want this.
So i need to have a way to only read "device created" data and not manually added data. Is there a nice way to to this?
From the SDK documentation it is not really clear how to proceed here.
So i need to have a way to only read "device created" data and not
manually added data. Is there a nice way to to this?
You will want to use Private Custom Data Types to achieve that. Read about the different types of Fitness data you can upload to Google Fit here.
1. Public data types
Standard data types provided by the platform, like com.google.step_count.delta. Any app can read and write data of
these types. For more information, see Public Data Types.
2. Private custom data types
Custom data types defined by an specific app. Only the app that defines the data type can read and write data
of this type. For more information, see Custom Data Types.
3. Shareable data types
Custom data types submitted to the platform by an app developer. Once approved, any app can read data of a
shareable type, but only whitelisted apps as specified by the
developer can write data of that shareable type. For more information,
see Shareable Data Types.
I was able to do this with the help of this alogrithm. But remember due to Android fragmentation this code still removes some of the user's data and count it as penalty
private String dumpDataSet(DataSet dataSet, int x) {
List<String> days = new ArrayList<>();
days.add("Monday");
days.add("Tuesday");
days.add("Wednesday");
days.add("Thursday");
days.add("Friday");
days.add("Saturday");
days.add("Sunday");
String day = days.get(Math.round(x / 24));
Log.d(TAG, "\tDay: " + day);
Log.i(TAG, "Data returned for Data type: " + dataSet.getDataType().getName());
DateFormat dateFormat = getTimeInstance();
String text = "";
try {
for (DataPoint dp : dataSet.getDataPoints()) {
Log.i(TAG, "\tStepCount getStreamName: " + dp.getOriginalDataSource().getStreamName());
Log.i(TAG, "\tStepCount getStreamIdentifier: " + dp.getOriginalDataSource().getStreamIdentifier());
Log.i(TAG, "\tStepCount App Type: " + dp.getDataType().getName());
Log.i(TAG, "\tStepCount Type: " + dp.getOriginalDataSource().getType());
for (Field field : dp.getDataType().getFields()) {
Log.i(TAG, "\tField: " + field.getName() + " Value: " + dp.getValue(field));
text += dp.getValue(field);
String si[] = dp.getOriginalDataSource().getStreamIdentifier().toLowerCase().split(":");
if ((((si[si.length - 1].contains("soft")) || (si[si.length - 1].contains("step"))) && si[si.length - 1].contains("counter"))) {
totalSteps += Integer.parseInt(dp.getValue(field).toString());
Log.d(TAG, "\tStepCount" + " Added Steps -> " + dp.getValue(field) + " steps");
text += "\n\n";
} else {
Log.e(TAG, "\tStepCount PENALTY ---------------------------------------------------------------");
Log.e(TAG, "\tDay = " + day + " | Hour Number = " + x + " | StepCount" + " PENALTY DEDUCTED -> " + dp.getValue(field) + " steps");
Log.e(TAG, "\tStepCount PENALTY getStreamIdentifier: " + dp.getOriginalDataSource().getStreamIdentifier());
Log.e(TAG, "\tStepCount PENALTY getStreamName: " + dp.getOriginalDataSource().getStreamName());
Log.e(TAG, "\tStepCount PENALTY App Type: " + dp.getDataType().getName());
Log.e(TAG, "\tStepCount PENALTY Type: " + dp.getOriginalDataSource().getType());
Log.e(TAG, "\tStepCount PENALTY ---------------------------------------------------------------");
}
}
}
} catch (Exception ex) {
ex.getStackTrace();
}
return text;
}
----- UPDATE -----
You can also call
DataPoint.getOriginalDataSource().getAppPackageName()
to filter out smartwatches and other apps.
I tried as suggested by Ali Shah lakhani but
DataPoint.getOriginalDataSource().getAppPackageName();
/*I also tried but could not achieve what I wanted*/
DataPoint.getOriginalDataSource().getStreamName();
DataPoint.getOriginalDataSource().getStreamIdentifier();
did not work at least for me while retrieving data. I ended up using readDailyTotalFromLocalDevice() as shown below in order to capture steps captured by device only.
Fitness.HistoryApi.readDailyTotalFromLocalDevice(mApiClient, DataType.TYPE_STEP_COUNT_DELTA).await(1, TimeUnit.MINUTES)
I cross checked the same with some of the apps that avoids manual entries in their app and the count provided by the function above is exactly the same.
Note: If a user is having multiple devices and is using the app on all of them, readDailyTotalFromLocalDevice() will have different value for each and every device since the function is responsible for returning device specific data only.
I am using Rhomobile (for Android) to post status update on Twitter. For that, following the steps of Oauth implementation I am able to get logged in with Twitter but after login, when trying to post the status update everytime I got HTTP Response as {"errors":[{"message":"Could not authenticate you","code":32}]}.
Below is the relevant code for making the request to post status update.
def post_to_twitter(comment)
$rnd = rand(36**32).to_s(36)
$post_status_url = "https://api.twitter.com/1.1/statuses/update.json"
$oauth_token1 = #account_set.tt_oauth_token
$oauth_token_secret1 = #account_set.tt_oauth_token_secret
#oauth_nonce = $rnd
#oauth_timestamp = Time.now.to_i.to_s
#http_port = System.get_property('rhodes_port')
#url_param = "oauth_consumer_key="+ $oauth_consumer_key + "&" +
"oauth_nonce=" + #oauth_nonce + "&" +
"oauth_signature_method=" + $oauth_signature_method + "&" +
"oauth_timestamp=" + #oauth_timestamp + "&" +
"oauth_token=" + $oauth_token1 + "&" +
"oauth_version="+ $oauth_version + "&" +
"status=" + Rho::RhoSupport.url_encode("Test")
$oauth_sign = get_auth_signature($post_status_url, #url_param, "")
#auth_header = "OAuth oauth_consumer_key="+ $oauth_consumer_key + ", " +
"oauth_nonce=" + #oauth_nonce + ", " +
"oauth_signature=" + $oauth_sign + ", " +
"oauth_signature_method=" + $oauth_signature_method + ", " +
"oauth_timestamp=" + #oauth_timestamp + ", " +
"oauth_token=" + $oauth_token1 + ", " +
"oauth_version="+ $oauth_version + ", " +
"status=" + Rho::RhoSupport.url_encode("Test")
postTTres = Rho::AsyncHttp.post(
:url => $post_status_url,
:headers =>{"Content-Type" => "application/x-www-form-urlencoded", "Authorization" => #auth_header }
)
p postTTres
end
The signature generation function is as follows:
def get_auth_signature (url, url_param, secret)
signature = "POST&" + Rho::RhoSupport.url_encode(url).to_s +
"&" + Rho::RhoSupport.url_encode(url_param).to_s
key = $oauth_consumer_secret + "&" + secret
hmac = HMAC::SHA1.new(key)
hmac.update(signature)
$signature = Base64.encode64("#{hmac.digest}")
$signature = Rho::RhoSupport.url_encode("#{$signature.gsub(/\n/,'')}")
return $signature
end
The parameters values when traced are as follows:
#url_param before generating signature ---------
oauth_consumer_key=2ChmEzWBe5Y9hMYODqA1IQ&oauth_non
ce=iyb9502vspjnhj9orb87sriych16678b&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1380117614&oauth_token=244586214-M6A2jMlR7vZiqwAMrfuSj7I7XFzFTRd4
6nV6aTLK&oauth_version=1.0&status=Test`
Passing #url_param to get_auth_signature() to generate signature.
Generated signature url and signature is
Signature string ----------
POST&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2Fupdate.
json&oauth_consumer_key%3D2ChmEzWBe5Y9hMYODqA1IQ%26oauth_nonce%3Diyb9502vspjnhj9orb87sriych16678b%26oauth_signature_method%3DHMAC-SHA1%26oauth_timesta
mp%3D1380117614%26oauth_token%3D244586214-M6A2jMlR7vZiqwAMrfuSj7I7XFzFTRd46nV6aTLK%26oauth_version%3D1.0%26status%3DTest"`
Base64 string -------
gjdXuU3qoGNt90Q2dRhNM3IXaBI%3D
Passing all these values as header Authorization to https://api.twitter.com/1.1/statuses/update.json
and got
Http Response as {"errors":[{"message":"Could not authenticate you","code":32}]}.
Also tried passing it as post parameters in :body but no luck.
postTTres = Rho::AsyncHttp.post(
:url => $post_status_url,
:headers =>{"Content-Type" => "application/x-www-form-urlencoded"},
:body => #url_param + "&oauth_signature=" + $oauth_sign
)
Checked the system timings with Twitter server timings and thats fine.
Also tried with static oauth_token that we can get from Twitter account but then too same response.
Please help me to fix this. I am unable to trace what I am missing or where I am going wrong.
Thanks
Two things:
The "status" parameter is a normal post data parameter, should not be in the authorization header, see https://dev.twitter.com/docs/api/1.1/post/statuses/update
There is a strange issue with API 1.1, with encoding special chars (like %20 for " "). The following did it for me: url encode the content of "status" for the input of the signature and do not encode it in the post data itself.
EDIT:
You forgot to supply the secret that corresponds to the user_token:
$oauth_sign = get_auth_signature($post_status_url, #url_param, "")
When you gain an access token from Twitter via https://api.twitter.com/oauth/access_token , twitter replies with an auth_token and an auth_token_secret (and the id and screen_name). You correctly supplied the auth_token in the params (and thereby to the signature), but you should supply the auth_token_secret where you currently put "".
EDIT 2:
Above edit makes me wonder: did you gain an access token using https://api.twitter.com/oauth/access_token ? Because for that you should use the oauth_token_secret that is a parameter in a call from twitter to the callback url supplied to https://api.twitter.com/oauth/request_token . This callback url is called as a response to confirmation of a user via https://api.twitter.com/oauth/authorize. For https://api.twitter.com/oauth/request_token you could use "" as a secret, since there is no auth_token yet in that phase (and thereby no corresponding secret).
I am using PhoneGap to develop an Android App. I am using ZXing plugin in order to scan a QR-Code.
In index.html, I put a button in order to scan a QR-Code:
<a href="#" onclick="scanCode();">
Here is the code of scanCode in the java-script file:
var scanCode = function() {
window.plugins.barcodeScanner.scan(
function(result) {
alert("Scanned Code: " + result.text
+ ". Format: " + result.format
+ ". Cancelled: " + result.cancelled);
}, function(error) {
alert("Scan failed: " + error);
});
}
I want to retrieve datas from "result", especially "result.text" in order to use them in another html file.
How can I please do it?
Thanks.
result.text is already the scanned text.
Try this:
var thetext = result.text;
https://github.com/phonegap/phonegap-plugins/tree/master/Android/BarcodeScanner talks about adding src.com.phonegap.plugins.barcodescanner.BarcodeScanner.java.