Reputation: 4103
I have problem that When we want to share a product with its image and text on facebook with the help of facebook sdk
(Fb Dialog) then it gives an error message as following:
Error Stack: *
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): FATAL EXCEPTION: main
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): java.lang.ArrayIndexOutOfBoundsException
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): at com.facebook.android.Util.decodeUrl(Util.java:96)
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): at com.facebook.android.Util.parseUrl(Util.java:115)
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): at com.facebook.android.FbDialog$FbWebViewClient.shouldOverrideUrlLoading(FbDialog.java:125)
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): at android.webkit.CallbackProxy.uiOverrideUrlLoading(CallbackProxy.java:224)
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): at android.webkit.CallbackProxy.handleMessage(CallbackProxy.java:349)
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): at android.os.Handler.dispatchMessage(Handler.java:99)
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): at android.os.Looper.loop(Looper.java:123)
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): at android.app.ActivityThread.main(ActivityThread.java:4627)
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): at java.lang.reflect.Method.invokeNative(Native Method)
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): at java.lang.reflect.Method.invoke(Method.java:521)
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-20 12:26:06.002: ERROR/AndroidRuntime(1776): at dalvik.system.NativeStart.main(Native Method)*
The code of Fb Dialog is as follows:
package com.shopzilla.android.listener;
import android.app.Activity;
import android.os.Bundle;
import com.shopzilla.android.client.model.BaseInventoryItem;
import com.shopzilla.android.moretab.SettingActivity;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;
/**
* A facebook dialog listener.
*
* @author Rod Barlow
* @since 7/21/11
*/
public class FacebookDialogListener implements DialogListener {
final BaseInventoryItem item;
final Activity activity;
public FacebookDialogListener(BaseInventoryItem item, Activity activity) {
this.item = item;
this.activity = activity;
}
@Override
public void onComplete(Bundle values) {
if (values.isEmpty()) {
//"skip" clicked ?
return;
}
if (!values.containsKey("post_id")) {
try {
Bundle parameters = new Bundle();
parameters.putString("attachment", "{\"name\":\"" + item.getTitle() + "\",\"href\":\"" + item.getUrl() + "\",\"description\":\" \", \"media\":[{\"type\":\"image\",\"src\":\"" + item.getImageUrl() + "\",\"href\":\"" + item.getUrl() + "\"}]}");
SettingActivity.mFacebook.dialog(activity, "stream.publish", parameters, new FacebookLoginDialogListener());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
@Override
public void onFacebookError(FacebookError e) {
System.out.println("Error: " + e.getMessage());
}
@Override
public void onError(DialogError e) {
System.out.println("Error: " + e.getMessage());
}
@Override
public void onCancel() {
}
}
Please Help me out about This problem.
Upvotes: 0
Views: 1269
Reputation: 4103
This Is Solved by a very easy Code as following:
In Util.java You must add this Line in a decode method:
if(v.length == 2)
{
param= /*as mentioned previous*/
}
And Issue Solved.
Upvotes: 1
Reputation: 1068
I had the same issue and i think i solved it.
Have a look at this:
https://stackoverflow.com/questions/7158224/another-problem-with-facebook-integration
Hope it helps!
Upvotes: 0
Reputation: 15
See the following page..
https://github.com/wrapp/facebook-android-sdk/commit/f226c110ff49b75b8a15d486a74e0295e05b8bd5
Upvotes: 1
Reputation: 2474
I'd suggest you use Graph API instead of REST. Changing to that may solve your problems. And it's much easier and more clear. Also, I remember I had to do some fixes in Facebook SDK in order to work correctly - I had similar problems with Util class. You may want to try out my fixed Facebook SDK implementation: http://www.2shared.com/file/0DFYym3f/facebookSDK.html
At some point you may get into trouble when trying to login to Facebook.
For example if you have Facebook application on your phone and you try to login in your app, you will be forwarded to that Facebook app and your callback will never be called. I fixed that in this implementation too so you don't depend on existing Facebook App, but you need to track access token for yourself. Example to do that would be something like this:
This should be put in some kind of 'Facebook manager'
public boolean restoreSession(Context context) {
if (preferences == null) {
preferences = PreferenceReader.getInstance(context);
}
return preferences.restoreFacebookSession(facebook, context);
}
public boolean saveSession(Context context) {
if (preferences == null) {
preferences = PreferenceReader.getInstance(context);
}
return preferences.saveFacebookSession(facebook, context);
}
And SharedPreferences should hold something like:
public boolean saveFacebookSession(Facebook facebook, Context context) {
editor.putString(TOKEN, facebook.getAccessToken());
editor.putLong(EXPIRES, facebook.getAccessExpires());
return editor.commit();
}
public boolean restoreFacebookSession(Facebook facebook, Context context) {
facebook.setAccessToken(preferences.getString(TOKEN, null));
facebook.setAccessExpires(preferences.getLong(EXPIRES, 0));
return facebook.isSessionValid();
}
Now when you receive false from restoreFacebookSession, you need to authorize and call saveFacebookSession. That's it :) Hope that helps to find a right way to use Facebook SDK \o/
Upvotes: 0