Upload
google-cloud-platform-japan
View
827
Download
8
Embed Size (px)
Citation preview
2015/04/11
バックエンドの構築は?
モバイル開発はチャレンジング
— 多数のプラットフォームで動く
— ユーザーはリアルタイム性を期待している
— 常に繋がっているデバイスは、アプリの状態が分散される
— 多数のデバイスは巨大なスケールが必要
2015/04/11
なんでFirebaseを使うと便利か
リアルタイムデータベース
● NoSQL, JSON データベース
● ミリ秒単位で更新をプッシュ
● デバイスから直接のアクセスを
可能とするセキュリティモデル
● データとURLのマッピング
01 / 23
2015/04/11
なんでFirebaseを使うと便利か
ユーザー管理
以下の方法で簡単にログイン:
● メアドとパスワード
● oAuthプロバイダー ○ Google○ Facebook○ Twitter○ Github
● カスタム認証トークン
2015/04/11
簡単なコーディング
Legal StuffCopyright (c) 2014 Firebase
Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.
2015/04/11
簡単なコーディング
ファイルホスティング
{ "firebase": "myfirebase", "public": "app", "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ]}
Java
2015/04/11
Create a new Google Apphttps://console.developers.google.com/project
1
Configure OAuth 2.0 Callbackhttps://auth.firebase.com/v2/<YOUR-FIREBASE>/auth/twitter/callback
2
Display Google Login Pop-Up3
var ref = new Firebase("https://<YOUR-FIREBASE>.firebaseio.com/");
ref.authWithOAuthPopup("google", function(error, authData) { ... });
簡単なコーディング
Example: Google認証を使う
2015/04/11
簡単なコーディング
Example: Google認証を使う
private void getGoogleOAuthTokenAndLogin() {
AsyncTask<Void, Void, String> task = new AsyncTask<>() {
@Override
protected String doInBackground(Void... params) {
String scope = String.format("oauth2:%s", Scopes.PLUS_LOGIN);
String token = GoogleAuthUtil.getToken(this,
Plus.AccountApi.getAccountName(mGoogleApiClient), scope);
return token;
}
...
Java
2015/04/11
簡単なコーディング
Example: Google認証を使うSubtitleJavaJava
...
@Override
protected void onPostExecute(String token) {
Intent intentWithToken = new Intent(this,
OfficeMoverActivity.class);
intentWithToken.putExtra(AUTH_TOKEN_EXTRA, token);
startActivity(intentWithToken);
}
}
2015/04/11
簡単なコーディング
Example: Google認証を使うSubtitleJava
mFirebaseRef.authWithOAuthToken("google", authToken, new
Firebase.AuthResultHandler() {
@Override
public void onAuthenticated(AuthData authData) {
Log.v(TAG, "Auth success");
}
@Override
public void onAuthenticationError(FirebaseError firebaseError) {
Toast.makeText(getApplicationContext(),
"Auth failed. Please try again",
Toast.LENGTH_SHORT).show();
}
});
Java
2015/04/11
簡単なコーディング
Example: オンライン状態
var amOnline = new Firebase('https://<YOUR-FIREBASE>.firebaseio.com/.
info/connected');
var presenceRef = new Firebase('https://<YOUR-FIREBASE>.firebaseio.
com/presence/'
+ userid);
amOnline.on('value', function(value) {
if (value.val() === true) {
// Connected (or reconnected)!
presenceRef.onDisconnect().set(false); // one off, has to be reregistered
presenceRef.set(true);
}
});
Java
2015/04/11
簡単なコーディング
Example: セキュリティ
"foo": { ... ".validate": "newData.isString() && newData.val().length < 100"}
Java
2015/04/11
簡単なコーディング
Example: セキュリティ
"users": { "$uid": { ".read": "auth != null && auth.uid == $uid" }}
Java
2015/04/11
簡単なコーディング
読み取りと書き込みSubtitleJavaScript
Firebase ref = new Firebase("https://<your-firebase>.firebaseio.com");
ref.child("background").setValue("grid");
ref.child("background").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
System.out.println(dataSnapshot.getValue()); // prints “grid”
}
@Override public void onCancelled(FirebaseError error) { }
});
2015/04/11
簡単なコーディング
読み取りと書き込みSubtitle Java
Firebase ref = new Firebase("https://<your-firebase>.firebaseio.com");
ref.child("background").setValue("grid");
ref.child("background").addValueEventListener(new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
System.out.println(dataSnapshot.getValue()); // prints “Grid”
}
@Override public void onCancelled(FirebaseError error) { }
});
2015/04/11
簡単なコーディング
読み取りと書き込みSubtitle Java
Firebase ref = new Firebase("https://<your-firebase>.firebaseio.com");
ref.child("background").setValue("grid");
ref.child("background").addValueEventListener(new ValueEventListener()
{
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
System.out.println(dataSnapshot.getValue()); // prints “grid”
}
...
});
2015/04/11
簡単なコーディング
読み取りと書き込みSubtitleJavaScript
OfficeThing newThing = new OfficeThing();
newThing.setName(“Don Quixote”);
ref.child("object").setValue(newThing);
/* This will replace the data at “object” with
"object" : {
"name" : "Don Quixote",
}
*/
2015/04/11
簡単なコーディング
読み取りと書き込みSubtitleJavaScript
Map<String, Object> name = new HashMap<String, Object>();
name.put(“name”, “Don Quixote”);
ref.child("object").update_children(name);
// You could also setValue() with the entire object
2015/04/11
これから
リリースする予定
● New! より強力なクエリー詳細はFirebaseブログまで
● 全プラットフォームのオフライン対応● よりいいユーザー管理とAnalytics● Google Cloud Platformとの連携
2015/04/11
Google Cloud Platformと連携する
Triggers
Firebase AppEngine BigQuery
Mobile Device
Sync
REST REST
これから
2015/04/11
これから
Google Cloud Platformと連携
“.trigger": {
“criteria": “data == ‘hello world’",
“method": “'POST'",
“target": “'https://my.externalservice.com/endpoint'",
“body": {
“text": “’someone said hello!’",
}
}
JSON
2015/04/11
Getting Started
firebase.com/tutorial