簡體   English   中英

奇怪的android-facebook分享按鈕

[英]Strange android-facebook share button

我已經在我的android項目中實現了facebook sdk。 我正在使用共享按鈕,該按鈕應將新消息發布到用戶時間軸。 一切正常,但是我想在手機上未安裝Facebook應用程序的情況下嘗試該應用程序。

我已經卸載了facebook,清除了緩存,清除了所有數據,從設置中刪除了“ Facebook帳戶”並重新啟動了手機。 之后,我按了我的應用程序中的“共享”按鈕,並且帖子在我的時間軸上! 這怎么可能? 我已經卸載了一切!

這是代碼。 我不知道這是否會有所幫助。

火盤

@Override
public void onClick(View v)
{
   switch(v.getId())
   {
      case R.id.btnFacebook:
         Session.openActiveSession(this, true, new Session.StatusCallback() {

                    @Override
                    public void call(Session session, SessionState state, Exception exception) {
                        if (session.isOpened()){
                            Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {

                                @Override
                                public void onCompleted(GraphUser user, Response response) {
                                    if (user != null){                              
                                        publishStory();
                                    }
                                }
                            });
                        }
                    }
                });

      break;
   }
}

private void publishStory() {
    Session session = Session.getActiveSession();

    if (session != null){

        // Check for publish permissions    
        List<String> permissions = session.getPermissions();
        if (!isSubsetOf(PERMISSIONS, permissions)) {
            Session.NewPermissionsRequest newPermissionsRequest = new Session
                    .NewPermissionsRequest(this, PERMISSIONS);
        session.requestNewPublishPermissions(newPermissionsRequest);
            return;
        }

        Bundle postParams = new Bundle();
        postParams.putString("name", "Something...");
        postParams.putString("caption", "My caption...");
        postParams.putString("description", "Awesomedescription");
        postParams.putString("link", "http://www.domain.com");
        postParams.putString("picture", "http://www.domain.com/image.png");

        Request.Callback callback= new Request.Callback() {
            public void onCompleted(Response response) {
                JSONObject graphResponse = response
                                           .getGraphObject()
                                           .getInnerJSONObject();
                String postId = null;
                try {
                    postId = graphResponse.getString("id");

                        Log.i("DEB", " SUCCESS POSTED TIMELINE ! ");


                } catch (JSONException e) {}
                FacebookRequestError error = response.getError();
                if (error != null) {
                    } else {
                        Toast.makeText(getApplicationContext(), 
                             postId,
                             Toast.LENGTH_LONG).show();
                }
            }
        };

        Request request = new Request(session, "me/feed", postParams, 
                              HttpMethod.POST, callback);

        RequestAsyncTask task = new RequestAsyncTask(request);
        task.execute();
    }

}

private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
    for (String string : subset) {
        if (!superset.contains(string)) {
            return false;
        }
    }
    return true;
}

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

Facebook應用程序和您的應用程序根本沒有捆綁在一起。 一旦您的應用程序獲得訪問令牌,就可以保留並重用它(即使您刪除了Facebook應用程序)。

SDK中的Session類將自動緩存令牌以供重用(這樣,當您打開一個新的Session時,它不會再次詢問用戶權限)。 如果要從應用程序注銷用戶,則應在應用程序關閉(或用戶選擇注銷)時調用session.closeAndClearTokenInformation()。

暫無
暫無

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

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