1

我正在使用Facebook SDK作爲外部庫的android.I能夠登錄通過facebook.But當我想共享圖像和應用程序尚未登錄通過Facebook,我試圖登錄,但在(幫助)在Android的Facebook SDK

W/com.facebook.Session(15670):不應將讀取權限(電子郵件)傳遞到發佈請求或管理授權 W/com.facebook.Session com.facebook.Session(15670):不應將讀取權限(read_friendlists)傳遞至發佈或管理授權請求

請找到代碼:

String[] permissions = { "email", 
      "user_birthday", 
      "publish_stream", 
      "user_checkins", 
      "friends_checkins", 
      "read_friendlists", 
      "publish_checkins", 
      "publish_actions" }; 
    final static int AUTHORIZE_ACTIVITY_RESULT_CODE = 0; 
facebook = new Facebook(APP_ID); 
            mAsyncRunner = new AsyncFacebookRunner(facebook); 
            facebook.authorize(getActivity(), permissions, AUTHORIZE_ACTIVITY_RESULT_CODE, 
              new DialogListener() { 


               public void onComplete(Bundle values) { 
                System.err.println("Inside oncomplete"); 
                //getProfileInformation(); 


               } 


               public void onFacebookError(FacebookError error) { 
                System.err.println(error.toString()+ "Facebook.authorize Error: "); 

                try { 
                 dialog.dismiss(); 
                } catch (Exception e) { 
                 // TODO: handle exception 
                } 
                dialog=null; 
               } 


               public void onError(DialogError e) { 
                System.err.println(e.toString()+ "Facebook.authorize DialogError: "); 
                Log.d(this.getClass().getName(), 
                  "Facebook.authorize DialogError: " 
                    + e.toString()); 
                try { 
                 dialog.dismiss(); 
                } catch (Exception e1) { 
                 // TODO: handle exception 
                } 
                dialog=null; 
               } 


               public void onCancel() { 
                System.err.println("Facebook authorization canceled"); 
                Log.d(this.getClass().getName(), 
                  "Facebook authorization canceled"); 
                try { 
                 dialog.dismiss(); 
                } catch (Exception e) { 
                 // TODO: handle exception 
                } 
                dialog=null; 
               } 
              }); 

           } 

          } 
         }); 

回答

1

第一次下載this Facebbok SDK並將其作爲庫項目包含在您的項目中。

在你的活動,在那裏你要共享的圖像::

private static Bitmap b; 
private static Facebook mFacebook; 
private static AsyncFacebookRunner mAsyncRunner; 
String[] permissions = {"photo_upload" }; 
final static int AUTHORIZE_ACTIVITY_RESULT_CODE = 0; 

的onCreate()初始化這個變量::從你要去哪裏分享

if (Constant.FACEBOOK_APP_ID == null) 
{ 
     Util.showAlert(this, "Warning", "Facebook Applicaton ID must be " 
         + "specified before running this example: see FbAPIs.java"); 
     return; 
} 

mHandler=new Handler(); 
mFacebook = new Facebook(Constant.FACEBOOK_APP_ID); 
mAsyncRunner = new AsyncFacebookRunner(mFacebook); 
SessionStore.restore(mFacebook, this); 


@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) 
{ 
    switch (requestCode) 
    { 
     case AUTHORIZE_ACTIVITY_RESULT_CODE: 
     { 
     mFacebook.authorizeCallback(requestCode, resultCode, data); 
     break; 
     } 
    } 
} 

onButtonClick a Image ::

if (!mFacebook.isSessionValid()) 
{ 
    mFacebook.authorize(TabNoteActivity.this, permissions, AUTHORIZE_ACTIVITY_RESULT_CODE, new LoginDialogListener()); 
} 
else 
{ 
    Bundle params = new Bundle(); 
    ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
    Utils.b.compress(Bitmap.CompressFormat.PNG, 100, stream);//Here I am convert the JPG image into bitmap using declaring method in the Utils class 
    byte[] byteArray = stream.toByteArray(); 
    params.putString (Facebook.TOKEN, mFacebook.getAccessToken()); 
    params.putString ("message"," Facebook App Testing"); 
    params.putByteArray("picture",byteArray); 
    mAsyncRunner.request("me/photos", params,"POST", new PhotoUploadListener(),null); 
} 


    public class PhotoUploadListener extends BaseRequestListener 
    { 
     //@Override 
     public void onComplete(final String response, final Object state) 
     { 

      mHandler.post(new Runnable() 
      { 
      // @Override 
      public void run() 
      { 
       Toast.makeText(Activity.this,"Image has been shared Successfully",Toast.LENGTH_LONG).show(); 
      } 
      }); 
     } 

     public void onFacebookError(FacebookError error) 
     { 
      Toast.makeText(getApplicationContext(), "Facebook Error: " + error.getMessage(),Toast.LENGTH_LONG).show(); 
     } 
}