簡體   English   中英

Facebook SDK Android-無法正常工作

[英]Facebook SDK Android - Not working

我對純粹的業余愛好者編碼感到很討厭。 我對C和PHP / mySQL有一定的經驗,因此可以讀一些代碼,也許還可以掌握不熟悉的語言。 任何幫助將不勝感激!

我最近一直在嘗試Android。 在玩過ATMEL IC和AVR編程后,這確實讓人喘不過氣來……但是我發現它令人沮喪的多了100倍!

我有一個基本的登錄腳本和活動,該腳本和活動允許通過loginmanager()函數登錄Facebook會話(類?Acitvity?View?Fragment?我還是不知道。從C,id稱為函數...)。

該應用程序請求如圖所示的相關權限,但是經過兩天的嘗試來弄清楚為什么……在調用LoginManager()函數之后,我似乎無法在OnComplete()函數中發生任何事情……

為什么我似乎無法成功登錄? 還是就此而言...甚至是“已取消”或“錯誤”登錄名?

    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





    }
}

這是布局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>

這是日志中的響應:

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: android.os.BinderProxy@7f76b34 time:69519776
I: Timeline: Activity_idle id: android.os.BinderProxy@6a43772 time:69519776
V: updateVisibility : ActivityRecord{215641b token=android.os.BinderProxy@6a43772 {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 token=android.os.BinderProxy@6a43772 {com.j3den.fibre/com.j3den.fibre.SplashScreen}} show : false
V: updateVisibility : ActivityRecord{aca09c4 token=android.os.BinderProxy@7f76b34 {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 token=android.os.BinderProxy@6a43772 {com.j3den.fibre/com.j3den.fibre.SplashScreen}} show : true
W: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
I: Timeline: Activity_idle id: android.os.BinderProxy@6a43772 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 token=android.os.BinderProxy@6a43772 {com.j3den.fibre/com.j3den.fibre.SplashScreen}} show : false
W: DisplayListCanvas is started on unbinded RenderNode (without mOwningView)
I: Timeline: Activity_idle id: android.os.BinderProxy@6a43772 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

您的logcat日志無用,沒有Facebook錯誤。 您可能在代碼中錯過了這一點:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);
}

請閱讀Facebook登錄教程

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM