2017-06-13 9 views
0

Ich habe Facebook Login zu meiner Anwendung hinzugefügt, aber wenn ich Facebook Button klicken, gibt es ERR_NAME_NOT_RESOLVED Fehler, bevor Sie mich fragen, irgendwelche Informationen.Facebook Login-Taste gibt Fehler die ganze Zeit

Hier sind meine Codes:

Meine 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); 
    } 
} 

Meine build.grade Datei

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' 

Meine Android-Manifest-Datei:

<?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 meine Klasse Name ist in Facebook festgelegt lopers Einstellung hinzugefügt app id meine strings.xml Datei

Vielen Dank im Voraus.

+0

Ich glaube nicht, dass Sie den Code zum Drücken der Login-Schaltfläche angegeben haben. – Jokab

+0

können Sie Ihren _activity_main.xml_ Code für die Login-Schaltfläche posten. –

+0

Warum erweitert Fragment Aktivität – Raj

Antwort

0

i geben einen vollständigen Code von Facebook-Integration mit App und u zunächst als Demo versuchen und nach in Ihrer App

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 implementieren sdk .jar Datei in Ihrem libs-Ordner und als Bibliothek im Projekt hier hinzufügen ist Link zum Herunterladen Facebook sdk facebook sdk

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

<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" /> 

Verwandte Themen