0
我想從我的Android應用程序發佈圖像到Facebook牆。我正在使用Facebook的SDK。Facebook錯誤API密鑰無效
從我MainActivity
當我打電話FBConnectionActivity
獲取連接和ID,我得到一個空指針異常
我打電話2個方法是這樣的: -
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
setConnection();
getID();
}
}
在FBConnectionActivity
,這兩個方法被定義爲:
public void setConnection() {
mContext = this;
mFacebook = Utility.mFacebook;
mAsyncRunner = new AsyncFacebookRunner(mFacebook);
}
public void getID(TextView txtUserName, ProgressBar progbar) {
username = txtUserName;
pb = progbar;
if (isSession()) {
Log.d(TAG, "sessionValid");
mAsyncRunner.request("me", new IDRequestListener());
} else {
// no logged in, so relogin
Log.d(TAG, "sessionNOTValid, relogin");
mFacebook.authorize(this, PERMS, new LoginDialogListener());
}
}
public void getID(){
if (isSession()) {
Log.d(TAG, "sessionValid");
mAsyncRunner.request("me", new IDRequestListener());
} else {
// no logged in, so relogin
Log.d(TAG, "sessionNOTValid, relogin");
mFacebook.authorize(this, PERMS, new LoginDialogListener());
}
}
在呼叫到isSession()
,該方法調用isSessionValid()
方法總是返回false。
public boolean isSession() {
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(mContext);
String access_token = sharedPrefs.getString("access_token", "x");
Long expires = sharedPrefs.getLong("access_expires", -1);
Log.d(TAG, access_token);
if (access_token != null && expires != -1) {
Log.e("isSession() method ", "acess_token : " + access_token);
mFacebook.setAccessToken(access_token);
mFacebook.setAccessExpires(expires);
}
return mFacebook.isSessionValid();
}
public boolean isSessionValid() {
return (getAccessToken() != null) &&
((getAccessExpires() == 0) ||
(System.currentTimeMillis() < getAccessExpires()));
}
如果我的會話無效,如何獲取新的有效訪問令牌。每當我嘗試從我的應用程序上傳圖像時,方法isSessionValid()
都會返回false。此外,我收到以下錯誤: -
01-18 12:46:35.928: D/Facebook-Example(28459): Response: {"error_code":101,"error_msg":"Invalid API key","request_args":[{"key":"method","value":"photos.upload"},{"key":"format","value":"json"}]}
01-18 12:46:35.948: W/Facebook-Example(28459): Facebook Error: Invalid API key
請幫幫我。
我使用以下方法在Facebook上發佈圖像。這裏有什麼不對嗎?
public void postImageonWall() {
Log.e("BrowsePictureActivity ", "Inside postImageonWall method");
byte[] data = null;
Bitmap bi = BitmapFactory.decodeFile(selectedImagePath);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
Log.d("BrowsePictureActivity ", "data.length : " + data.length);
Bundle params = new Bundle();
params.putString("method", "photos.upload");
params.putByteArray("picture", data);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new SampleUploadListener(),
null);
}
我使用下面的方法對在Facebook上張貼的圖像。這裏有什麼不對嗎? –
嘗試上面的片段伴侶。 – Venky
@Swati Rawat如果答案是有用的,只要接受它。 – Venky