[英]Facebook login button gives error all the time
I added facebook login to my application but wheneven i click facebook button it gives ERR_NAME_NOT_RESOLVED error before asking me any info. 我在我的应用程序中添加了Facebook登录名,但是即使我单击facebook按钮,在询问我任何信息之前,它也会显示ERR_NAME_NOT_RESOLVED错误。
Here are my codes: 这是我的代码:
My java: 我的java:
package com.bogroup.ucuncuprogram;
import android.content.Intent;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.login.LoginManager;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
public class Fireapp extends FragmentActivity {
CallbackManager callbackManager;
TextView txtstatus;
LoginButton loginButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fireapp);
txtstatus = (TextView) findViewById(R.id.textView4);
callbackManager = CallbackManager.Factory.create();
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions("email");
loginButton.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
gir();
}
});
}
private void gir() {
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
txtstatus.setText("basarili "+loginResult.getAccessToken());
}
@Override
public void onCancel() {
txtstatus.setText("iptal");
}
@Override
public void onError(FacebookException error) {
txtstatus.setText("hata "+error.getMessage());
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
My build.grade file 我的build.grade文件
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.3"
defaultConfig {
applicationId "com.bogroup.ucuncuprogram"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
packagingOptions {
exclude 'META-INF/NOTICE' // will not include NOTICE file
exclude 'META-INF/LICENSE' // will not include LICENSE file
// as noted by @Vishnuvathsan you may also need to include
// variations on the file name. It depends on your dependencies.
// Some other common variations on notice and license file names
exclude 'META-INF/notice'
exclude 'META-INF/notice.txt'
exclude 'META-INF/license'
exclude 'META-INF/license.txt'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
ext {
googlePlayVer = "10.2.0"
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.0.0'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
compile "com.google.android.gms:play-services-auth:${googlePlayVer}"
compile "com.google.firebase:firebase-core:${googlePlayVer}"
compile "com.google.firebase:firebase-auth:${googlePlayVer}"
compile "com.google.firebase:firebase-database:${googlePlayVer}"
compile "com.google.firebase:firebase-crash:${googlePlayVer}"
compile "com.firebaseui:firebase-ui:1.2.0"
compile 'com.android.support:animated-vector-drawable:25.0.0'
compile 'com.android.support:design:25.0.0'
compile 'com.android.support:support-v4:25.0.0'
compile 'com.android.support:cardview-v7:25.0.0'
compile 'com.android.support:customtabs:25.0.0'
compile 'com.android.support:recyclerview-v7:25.0.0'
compile 'com.squareup.picasso:picasso:2.5.2'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
My android manifest file: 我的Android清单文件:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.bogroup.ucuncuprogram">
<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"
>
<meta-data android:name="com.facebook.sdk.ApplicationId"
tools:replace="android:value"
android:value="@string/facebook_app_id"/>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".ikinciekren">
<intent-filter>
<action android:name="android.intent.action.IKINCIEKREN" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Fireapp">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Btw my class name is set in facebook developers setting added app id my strings.xml file 顺便说一句,我的类名是在Facebook开发人员中设置的,设置了添加的应用程序ID我的strings.xml文件
Thanks in advance. 提前致谢。
i give a full code of facebook integration with app and first u try as a demo and after implement in your app 我给出了Facebook与应用程序集成的完整代码,首先您尝试作为演示,然后在您的应用程序中实施
MainActivity.java MainActivity.java
public class MainActivity extends AppCompatActivity {
CallbackManager callbackManager;
Button share, details;
ShareDialog shareDialog;
LoginButton login;
ProfilePictureView profile;
Dialog details_dialog;
TextView details_txt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
callbackManager = CallbackManager.Factory.create();
login = (LoginButton) findViewById(R.id.login_button);
profile = (ProfilePictureView) findViewById(R.id.picture);
shareDialog = new ShareDialog(this);
share = (Button) findViewById(R.id.share);
details = (Button) findViewById(R.id.details);
login.setReadPermissions("public_profile email");
share.setVisibility(View.INVISIBLE);
details.setVisibility(View.INVISIBLE);
details_dialog = new Dialog(this);
details_dialog.setContentView(R.layout.dialog_details);
details_dialog.setTitle("Details");
details_txt = (TextView) details_dialog.findViewById(R.id.details);
details.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
details_dialog.show();
}
});
if (AccessToken.getCurrentAccessToken() != null) {
RequestData();
share.setVisibility(View.VISIBLE);
details.setVisibility(View.VISIBLE);
}
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (AccessToken.getCurrentAccessToken() != null) {
share.setVisibility(View.INVISIBLE);
details.setVisibility(View.INVISIBLE);
profile.setProfileId(null);
}
}
});
share.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ShareLinkContent content = new ShareLinkContent.Builder().build();
shareDialog.show(content);
}
});
login.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
if (AccessToken.getCurrentAccessToken() != null) {
RequestData();
share.setVisibility(View.VISIBLE);
details.setVisibility(View.VISIBLE);
}
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException exception) {
}
});
}
public void RequestData() {
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
JSONObject json = response.getJSONObject();
try {
if (json != null) {
String text = "<b>Name :</b> " + json.getString("name") + "<br><br><b>Email :</b> " + json.getString("email") + "<br><br><b>Profile link :</b> " + json.getString("link");
details_txt.setText(Html.fromHtml(text));
profile.setProfileId(json.getString("id"));
}
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link,email,picture");
request.setParameters(parameters);
request.executeAsync();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
} }
put facebook sdk .jar file in your libs folder and add as a library in project here is link to download facebook sdk facebook sdk 将facebook sdk .jar文件放入您的libs文件夹中,并作为库添加到项目中,这里是下载facebook sdk的链接facebook sdk
manifest.xml manifest.xml
<uses-permission android:name="android.permission.INTERNET">
</uses-permission>
<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">
<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" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<!--<category android:name="android.intent.category.DEFAULT" />-->
<!--<category android:name="android.intent.category.BROWSABLE" />-->
<data android:scheme="@string/fb_login_protocol_scheme" />
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
mainactivity.xml mainactivity.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<com.facebook.login.widget.ProfilePictureView
android:id="@+id/picture"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_width="200sp"
android:layout_height="200sp"/>
<com.facebook.login.widget.LoginButton
android:id="@+id/login_button"
android:layout_width="200sp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp" />
<Button
android:id="@+id/details"
android:text="Show details"
android:layout_gravity="center"
android:layout_width="200sp"
android:layout_marginBottom="20dp"
android:layout_height="wrap_content" />
<Button
android:id="@+id/share"
android:text="Share"
android:layout_gravity="center"
android:layout_width="200sp"
android:layout_height="wrap_content" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.