Ich bin ziemlich noobish mit Codierung als reiner Hobbyist. Ich habe etwas Erfahrung mit C und PHP/mySQL, also kann Art Code lesen und vielleicht den Kern in den fremden Sprachen erhalten. Jede Hilfe würde sehr geschätzt werden!Facebook SDK Android - funktioniert nicht
Ich habe kürzlich versucht, meine Hand bei Android. Nach dem Spielen mit ATMEL ICs und AVR-Programmierung ist es eine ziemliche Verschnaufpause ... aber ich finde es auch ungefähr 100x frustrierender!
Ich habe eine grundlegende Anmeldeskript und Aktivität, die einer Facebook-Sitzung Anmeldung über die Loginmanager() Funktion (Klasse? Acitvity? View? Fragment? Ich habe noch keine Ahnung. Von C, id nennt es eine Funktion ermöglichen sollte, ...).
Die App fordert die relevanten Berechtigungen wie angezeigt, aber nach jetzt 2 Tagen zu versuchen, herauszufinden, warum ... Ich kann scheinbar nichts in der OnComplete() -Funktion auftreten, nachdem die LoginManager() -Funktion aufgerufen wird ...
Warum scheine ich nicht eine erfolgreiche Anmeldung zu bekommen? Oder sogar ... sogar ein "Canceled" oder "Error" Login?
package com.j3den.fibre;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.facebook.AccessToken;
import com.facebook.CallbackManager;
import com.facebook.FacebookCallback;
import com.facebook.FacebookException;
import com.facebook.FacebookSdk;
import com.facebook.GraphRequest;
import com.facebook.GraphResponse;
import com.facebook.HttpMethod;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.login.LoginManager;
import com.facebook.login.LoginResult;
import com.facebook.login.widget.LoginButton;
import com.facebook.share.model.ShareLinkContent;
import com.facebook.share.widget.ShareDialog;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Text;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class SplashScreen extends AppCompatActivity {
List<String> permissionNeeds = Arrays.asList("email","public_profile","user_likes");
String stuff ="";
public static CallbackManager callbackManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d("DEBUG ", "================================STARTING=============================================");
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_splash_screen);
super.onCreate(savedInstanceState);
AppEventsLogger.activateApp(this);
LoginManager.getInstance().logInWithReadPermissions(this, permissionNeeds);
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
// ON SUCCESSFUL LOGIN...DO A REQUEST
public void onSuccess(LoginResult loginResult) {
Log.d("DEBUG ", "================================LOGIN SUCCESS=============================================");
TextView infobox = (TextView) findViewById(R.id.textView);
infobox.setText(loginResult.getAccessToken().getUserId());
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
try {
stuff = object.getString("email");
Log.d("CRAP>>>>>>>i>", stuff);
}
catch (JSONException e) {
Log.e("ERR","ERROR!!!!!!!!!!!!!!!!!!!!") ;
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "email,public_profile");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
Log.e("dd", "facebook login canceled");
}
@Override
public void onError(FacebookException error) {
Log.e("dd", "facebook login failed error");
}
}); // Close Login manager
}
}
Dies ist das Layout XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.j3den.fibre.SplashScreen"
android:id="@+id/login_button">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="InfoBox"
android:id="@+id/textView"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:editable="true" />
</RelativeLayout>
Dies ist die Antwort im Log:
W: getTopLevelResources: /data/app/com.j3den.fibre-1/base.apk/1.0 running in com.j3den.fibre rsrc of package null
W: ClassLoader referenced unknown path: /data/app/com.j3den.fibre-1/lib/arm
W: Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error
W: ClassLoader referenced unknown path: /data/app/com.j3den.fibre-1/lib/arm
W: getTopLevelResources: /data/app/com.j3den.fibre-1/base.apk/1.0 running in com.j3den.fibre rsrc of package null
W: getTopLevelResources: /data/app/com.j3den.fibre-1/base.apk/1.0 running in com.j3den.fibre rsrc of package null
D: ================================STARTING=============================================
I: (HTTPLog)-Static: isSBSettingEnabled false
I: (HTTPLog)-Static: isSBSettingEnabled false
W: remove failed: ENOENT (No such file or directory) : /data/user/0/com.j3den.fibre/files/AppEventsLogger.persistedevents
W: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
W: remove failed: ENOENT (No such file or directory) : /data/user/0/com.j3den.fibre/files/AppEventsLogger.persistedsessioninfo
I: Timeline: Activity_launch_request id:com.j3den.fibre time:69519232
D: Metadata value : none
D: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{fc87c3 I.E...... R.....ID 0,0-0,0}
D: Use EGL_SWAP_BEHAVIOR_PRESERVED: true
I: <qeglDrvAPI_eglInitialize:379>: EGL 1.4 QUALCOMM build: (Ia10634f51b)
OpenGL ES Shader Compiler Version: E031.29.00.00
Build Date: 01/28/16 Thu
Local Branch: ss
Remote Branch:
Local Patches:
Reconstruct Branch:
D: eglInitialize EGLDisplay = 0x9e8fa7c4
I: Initialized EGL, version 1.4
W: remove failed: ENOENT (No such file or directory) : /data/user/0/com.j3den.fibre/shared_prefs/com.facebook.sdk.appEventPreferences.xml.bak
W: getTopLevelResources: /data/app/com.j3den.fibre-1/base.apk/1.0 running in com.j3den.fibre rsrc of package null
D: Warning: Request without access token missing application ID or client token.
I: (HTTPLog)-Static: isSBSettingEnabled false
I: (HTTPLog)-Static: isSBSettingEnabled false
D: Metadata value : none
D: #1 mView = com.android.internal.policy.PhoneWindow$DecorView{dbc56d2 I.E...... R.....I. 0,0-0,0}
D: MSG_RESIZED_REPORT: ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1
W: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
W: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
D: MSG_RESIZED_REPORT: ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 0) or=1
W: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
I: Timeline: Activity_idle id: [email protected] time:69519776
I: Timeline: Activity_idle id: [email protected] time:69519776
V: updateVisibility : ActivityRecord{215641b [email protected] {com.j3den.fibre/com.j3den.fibre.SplashScreen}} show : true
W: remove failed: ENOENT (No such file or directory) : /data/user/0/com.j3den.fibre/shared_prefs/com.facebook.internal.preferences.APP_SETTINGS.xml.bak
W: remove failed: ENOENT (No such file or directory) : /data/user/0/com.j3den.fibre/shared_prefs/com.facebook.sdk.attributionTracking.xml.bak
I: Timeline: Activity_launch_request id:com.facebook.katana time:69521892
V: updateVisibility : ActivityRecord{215641b [email protected] {com.j3den.fibre/com.j3den.fibre.SplashScreen}} show : false
V: updateVisibility : ActivityRecord{aca09c4 [email protected] {com.j3den.fibre/com.facebook.FacebookActivity}} show : false
W: remove failed: ENOENT (No such file or directory) : /data/user/0/com.j3den.fibre/files/AppEventsLogger.persistedevents
I: (HTTPLog)-Static: isSBSettingEnabled false
I: (HTTPLog)-Static: isSBSettingEnabled false
V: updateVisibility : ActivityRecord{215641b [email protected] {com.j3den.fibre/com.j3den.fibre.SplashScreen}} show : true
W: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
I: Timeline: Activity_idle id: [email protected] time:69550856
D: #3 mView = null
D: ViewPostImeInputStage processPointer 0
D: ViewPostImeInputStage processPointer 1
D: ViewPostImeInputStage processPointer 0
D: ViewPostImeInputStage processPointer 1
D: ViewPostImeInputStage processPointer 0
D: ViewPostImeInputStage processPointer 1
D: ViewPostImeInputStage processPointer 0
D: ViewPostImeInputStage processPointer 1
D: ViewPostImeInputStage processPointer 0
D: ViewPostImeInputStage processPointer 1
D: ViewPostImeInputStage processPointer 0
D: ViewPostImeInputStage processPointer 1
V: updateVisibility : ActivityRecord{215641b [email protected] {com.j3den.fibre/com.j3den.fibre.SplashScreen}} show : false
W: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
I: Timeline: Activity_idle id: [email protected] time:69562562
W: remove failed: ENOENT (No such file or directory) : /data/user/0/com.j3den.fibre/files/AppEventsLogger.persistedevents
I: (HTTPLog)-Static: isSBSettingEnabled false
I: (HTTPLog)-Static: isSBSettingEnabled false