facebook_login_api
//login page with facebook google ma facebook with developers search karvu
//doc ma click karvanu and facebool login ma jvanu
//android pr click karvanu and string ,manifest,ma ietle vastu add kre devani
//save kre ne and pkg name add kre ne save kre devu vedio ma joi ne
//How to Integrate Facebook Login with your Android Application youtube : https://www.youtube.com/watch?v=SrAXmZkOpJI
/facebook developer ma accout bnavvanu
Step 1:xml
step 2:java
step 3:string //aama facebook ma developer opdion ma je string hoy ae j copy karve aa ma kbr pde ietle string lidhe che aa string copy karvi nai
step 4:manifest
step 5:graddle
Step 1:xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
tools:context="demoproject.aalap.com.loginfacebook.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Login_Status"
android:id="@+id/textview"
android:gravity="center"/>
<com.facebook.login.widget.LoginButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fb_login_bn"
android:layout_centerInParent="true"/>
</RelativeLayout>
Step 2:activity.java
public class MainActivity extends AppCompatActivity{
LoginButton loginButton;
TextView textView;
CallbackManager callbackManager;
private static final String TAG = "tag";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
printHashKey(getApplicationContext());
loginButton = findViewById(R.id.fb_login_bn);
textView = findViewById(R.id.textview);
callbackManager = CallbackManager.Factory.create();
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
textView.setText("login sucess\n"+
"\n"+loginResult.getAccessToken().getUserId()+
"\n"+loginResult.getAccessToken().getToken());
}
@Override
public void onCancel() {
textView.setText("login cancel");
}
@Override
public void onError(FacebookException error) {
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode,resultCode,data);
}
// }
public void printHashKey(Context pContext) {
try {
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String hashKey = new String(Base64.encode(md.digest(), 0));
Log.i(TAG, "printHashKey() Hash Key: " + hashKey);
}
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "printHashKey()", e);
} catch (Exception e) {
Log.e(TAG, "printHashKey()", e);
}
}
}
Step 3:String.xml
<resources>
<string name="app_name">loginfacebook</string>
<string name="facebook_app_id">2132764310268608</string>
<string name="fb_login_protocol_scheme">fb2132764310268608</string>
</resources>
Step 4:Mainifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="demoproject.aalap.com.loginfacebook">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
</application>
</manifest>
Step 5:graddle(module:app)
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.facebook.android:facebook-android-sdk:4.5.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
//doc ma click karvanu and facebool login ma jvanu
//android pr click karvanu and string ,manifest,ma ietle vastu add kre devani
//save kre ne and pkg name add kre ne save kre devu vedio ma joi ne
//How to Integrate Facebook Login with your Android Application youtube : https://www.youtube.com/watch?v=SrAXmZkOpJI
/facebook developer ma accout bnavvanu
Step 1:xml
step 2:java
step 3:string //aama facebook ma developer opdion ma je string hoy ae j copy karve aa ma kbr pde ietle string lidhe che aa string copy karvi nai
step 4:manifest
step 5:graddle
Step 1:xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="16dp"
tools:context="demoproject.aalap.com.loginfacebook.MainActivity">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Login_Status"
android:id="@+id/textview"
android:gravity="center"/>
<com.facebook.login.widget.LoginButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/fb_login_bn"
android:layout_centerInParent="true"/>
</RelativeLayout>
Step 2:activity.java
public class MainActivity extends AppCompatActivity{
LoginButton loginButton;
TextView textView;
CallbackManager callbackManager;
private static final String TAG = "tag";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
printHashKey(getApplicationContext());
loginButton = findViewById(R.id.fb_login_bn);
textView = findViewById(R.id.textview);
callbackManager = CallbackManager.Factory.create();
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
textView.setText("login sucess\n"+
"\n"+loginResult.getAccessToken().getUserId()+
"\n"+loginResult.getAccessToken().getToken());
}
@Override
public void onCancel() {
textView.setText("login cancel");
}
@Override
public void onError(FacebookException error) {
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
callbackManager.onActivityResult(requestCode,resultCode,data);
}
// }
public void printHashKey(Context pContext) {
try {
PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES);
for (Signature signature : info.signatures) {
MessageDigest md = MessageDigest.getInstance("SHA");
md.update(signature.toByteArray());
String hashKey = new String(Base64.encode(md.digest(), 0));
Log.i(TAG, "printHashKey() Hash Key: " + hashKey);
}
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "printHashKey()", e);
} catch (Exception e) {
Log.e(TAG, "printHashKey()", e);
}
}
}
Step 3:String.xml
<resources>
<string name="app_name">loginfacebook</string>
<string name="facebook_app_id">2132764310268608</string>
<string name="fb_login_protocol_scheme">fb2132764310268608</string>
</resources>
Step 4:Mainifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="demoproject.aalap.com.loginfacebook">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
</application>
</manifest>
Step 5:graddle(module:app)
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.facebook.android:facebook-android-sdk:4.5.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}
Comments
Post a Comment