2017-03-11 99 views
1

在下面的代碼我使用的Facebook提供鉻自定義標籤的特徵, Facebook登錄屏幕在兩個鉻打開(如果具有鉻瀏覽器裝置)在facebook的應用程序或其他簡單web視圖,並且還(如果具有的應用程序裝置)但在授予一般許可後,graphapi即使在異步調用後也沒有提供任何數據,但我沒有得到我在做什麼錯誤,請儘可能幫助Facebook的機器人登錄

額外信息: - 這是在片段內調用facebook登錄屏幕是在所有三種方式開放只是回調不工作,直到現在我無法找到解決方案,這隻有得到未答覆的問題,他們的任何方式,我們可以聯繫Facebook的這一點。

依賴性的gradle

compile 'com.facebook.android:facebook-android-sdk:[4,5)' 

Android清單代碼

<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="com.facebook.CustomTabActivity" 
     android:exported="true"> 
     <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" /> 
     </intent-filter> 
    </activity> 

登錄碼

facebook_sign.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      mCallbackManager = CallbackManager.Factory.create(); 
      LoginManager.getInstance().logInWithReadPermissions(getActivity(), App_Contants.PERMISSIONS); 
      LoginManager.getInstance().registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() { 
       @Override 
       public void onSuccess(LoginResult loginResult) { 
        GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() { 
         @Override 
         public void onCompleted(JSONObject object, GraphResponse response) { 
          try { 
           final String id = object.getString("id"); 
           final String name = object.getString("name"); 
           final String email = object.getString("email"); 
           final String gender = object.getString("gender"); 
           final String picture = object.getJSONObject("picture").getJSONObject("data").getString("url"); 
           final String data = id + ", " + name + ", " + email + ", " + gender + ", "+ ", " + picture; 
           Log.e("my_data", response.getRawResponse()); 
          } catch (JSONException e) { 
           e.printStackTrace(); 
          } 
         } 
        }); 
        Bundle parameters = new Bundle(); 
        parameters.putString("fields", "id,name,email,gender,picture.width(400).height(400)"); 
        request.setParameters(parameters); 
        request.executeAsync(); 
       } 

       @Override 
       public void onCancel() { 
        Toast.makeText(mContext,"Facebook Login Cancel",Toast.LENGTH_SHORT).show(); 
       } 

       @Override 
       public void onError(FacebookException error) { 
        error.printStackTrace(); 
       } 
      }); 
     } 
    }); 


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

    if (resultCode == Activity.RESULT_OK) { 
     mCallbackManager.onActivityResult(requestCode, resultCode, data); 
    } 

    // Result returned from launching the Intent from 
    // GoogleSignInApi.getSignInIntent(...); 
    if (requestCode == 1) { 
     GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 
     if (result.isSuccess()) { 
      GoogleSignInAccount acct = result.getSignInAccount(); 
      // Get account information 
      Log.e("data",acct.getEmail()); 

      mGoogleApiClient.stopAutoManage(getActivity()); 
      mGoogleApiClient.disconnect(); 
     }else if(result.getStatus().isCanceled()){ 
      mGoogleApiClient.stopAutoManage(getActivity()); 
      mGoogleApiClient.disconnect(); 
     }else if(result.getStatus().isInterrupted()){ 
      mGoogleApiClient.stopAutoManage(getActivity()); 
      mGoogleApiClient.disconnect(); 
     }else{ 
      mGoogleApiClient.stopAutoManage(getActivity()); 
      mGoogleApiClient.disconnect(); 
     } 
    } 
} 

回答

1

終於找到了解決方案。那麼當你在片段這樣做,你必須做出

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

的活動也因爲這個SDK觸發,在活動從他們的,你必須將它傳遞給你的片段(與你的loginfragment替換片段)

+0

我我堅持同樣的問題,我只是想獲取有關android的數據。我遵循你的解決方案,但沒有奏效。我想要一些用戶數據,例如片段上的fname,lastname。你可以幫我嗎? – Bishwash

+0

是的,你能提供你的場景,你是如何努力實現它。 – antoniomerlin