Facebook error : application ID is invalid - android

Hey i get this error using the SDK though the app ID is correct.
Now when i try to authorize the app, it works fine and authorizes it, but when i try and make requests, facebook returns this error. My app is initlized properly and is not in sandbox mode.
I found No info about this problem, does someone know what can cause this?
I'm trying to upload photo using The following code :
byte[] data = null;
Bitmap bi = BitmapFactory.decodeFile(photoToPost);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bi.compress(Bitmap.CompressFormat.JPEG, 100, baos);
data = baos.toByteArray();
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);
SampleUploadListener :
public class SampleUploadListener extends BaseRequestListener {
public void onComplete(final String response, final Object state) {
try {
// process the response here: (executed in background thread)
Log.d("Facebook-Example", "Response: " + response.toString());
JSONObject json = Util.parseJson(response);
final String src = json.getString("src");
// then post the processed result back to the UI thread
// if we do not do this, an runtime exception will be generated
// e.g. "CalledFromWrongThreadException: Only the original
// thread that created a view hierarchy can touch its views."
} catch (JSONException e) {
Log.w("Facebook-Example", "JSON Error in response");
} catch (FacebookError e) {
Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
}
}
#Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
}

I Solved the problem.
THe problem was i created 2 instances of the Facebook object, one as global and one inside the method preforming the code mentioned above, So what happened is i never authorized the Object i tried doing the request is.
For some reason the error dosen't say that but in case this happens to you, make sure you have initialised the right Object and it has a valid session

Related

Problems when creating Open Graph stories: "unable to generate story" and "failed to generate preview"

I have an app on Facebook (we'll call it mygame), connected with an Android game I'm developing.
In this mobile app, I want to let users to share their scores after a match. For this, I've considered the use of Open Graph stories, actions and objects.
The first thing I've done is to create an action, "Play" and an object "Match", this one with an integer property named "score".
After that, I've created my first story in the form "Play a Match" using the relative button "Add custom story".
First problem: all the generated examples don't show a preview, instead a red message appears, Unable to Generate Story.
This problem was previously treated on Stackoverflow, and the cause was related to the fact that "facebook has no examples of the story to render".
That should not be true in my case, because if I open the Object Browser I can see two auto-generated Match objects. Does Facebook try to generate example stories from those records?
If not (or even true), what's the problem?
Second problem SOLVED, SEE ANSWERS: on Android, simply, I can't test this story due to an exception that says com.facebook.FacebookException: Failed to generate preview for user..
The method I've used to show a Facebook Dialog with the details of this "played match" is the one described here: https://developers.facebook.com/docs/android/open-graph#sharedialog-setup
In my app, the code is the following:
OpenGraphObject setObj = OpenGraphObject.Factory.createForPost("mygame:match");
setObj.setProperty("score", set.getThisUserScore());
setObj.setProperty("title", set.getType().getDisplayString());
setObj.setProperty("url", "http://www.mygame.com");
setObj.setProperty("description", "Can you beat me?");
OpenGraphAction action = GraphObject.Factory.create(OpenGraphAction.class);
action.setType("mygame:play");
action.setProperty("match", setObj);
FacebookDialog shareDialog = new FacebookDialog.OpenGraphActionDialogBuilder(activity, action, "match").build();
activity.getUiHelper().trackPendingDialogCall(shareDialog.present());
Once called, the Dialog appears on my device, but it closes itself after one second, throwing the exception.
I really can't focus on where the problem is (I'm trying to implement the simplest way of sharing stories). Are these two problems connected?
I use this code to publish on wall for multiple object properties.
private void publishPhoto(String imageURL) {
Log.d("FACEBOOK", "Post to Facebook!");
try {
JSONObject attachment = new JSONObject();
attachment.put("message",text);
attachment.put("name", "MyGreatAndroidAppTest");
attachment.put("href", "http://stackoverflow.com/users/909317/sunny");
attachment.put("description","Test Test TEst");
JSONObject media = new JSONObject();
media.put("type", "image");
media.put("src", imageURL);
media.put("href",imageURL);
attachment.put("media", new JSONArray().put(media));
JSONObject properties = new JSONObject();
JSONObject prop1 = new JSONObject();
prop1.put("text", "Text or captionText to Post");
prop1.put("href", imageURL);
properties.put(text, prop1);
// u can make any number of prop object and put on "properties" for ex: //prop2,prop3
attachment.put("properties", properties);
Log.d("FACEBOOK", attachment.toString());
Bundle params = new Bundle();
params.putString("attachment", attachment.toString());
facebook.dialog(MyProjectActivity.this, "stream.publish", params, new DialogListener() {
#Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
#Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
#Override
public void onComplete(Bundle values) {
final String postId = values.getString("post_id");
if (postId != null) {
Log.d("FACEBOOK", "Dialog Success! post_id=" + postId);
Toast.makeText(MyProjectActivity.this, "Successfully shared on Facebook!", Toast.LENGTH_LONG).show();
} else {
Log.d("FACEBOOK", "No wall post made");
}
}
#Override
public void onCancel() {
// TODO Auto-generated method stub
}
});
} catch (JSONException e) {
Log.e("FACEBOOK", e.getLocalizedMessage(), e);
}
}
I've solved the second problem about the FacebookException!
There's a wrong line:
setObj.setProperty("score", set.getThisUserScore());
Being "score" a custom property, the line must be replaced by:
setObj.getData().setProperty("score", set.getThisUserScore());
Note that I had to search deeply in the documentation to find this...

difficulty in posting videos on facebook

I am making an application in which i want to post videos on facebook.While i try to do that,i am getting this error:
Facebook Error: (#100) Requires extended permission: video_upload or Requires extended permission: publish_actions
This is the code:
mUploadButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
byte[] data = null;
AssetFileDescriptor fileDesc = getResources().openRawResourceFd(
R.raw.movie);
String dataPath = fileDesc.toString();
String dataMsg = "Your video description here.";
String dataName = "movie.mp4";
Bundle param;
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook);
InputStream is ;
try
{
is = fileDesc.createInputStream();
// is = new FileInputStream(dataPath);
if(is != null)
data = readBytes(is);
param = new Bundle();
param.putString("message", dataMsg);
param.putString("filename", dataName);
param.putByteArray("video", data);
mAsyncRunner.request("me/videos", param, "POST", new SampleRequestListener(), null);
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
});
Please tell me what is the problem and how to solve it.
The problem is contained in the error message. It is a fairly clear error message I think.
In the Authentication flow for your app, you have not requested that the user grant you the video_upload, publish_actions or publish_stream Permission - any of those three will allow video uploads, but the third is more wide-ranging and triggers a second page on the auth dialog.
Check whichever SDK you're using to see if it has a convenient wrapper to ask for additional permissions in the auth flow. In the regular Oauth flow, you just add the list of permissions needed as the scope parameter in your call to the Oauth dialog

Error in obtaining public access token for Mobli

I am having is issues in obtaining the public access token for my app. I am getting the following error:
05-26 14:43:17.194: D/Mobli(1219): Response {"error":"invalid_request","error_description":"The request includes an unsupported parameters","error_uri":"http://dev.mobli.com/error/invalid_request"}
The code that I am using to make the request is as follows:
Mobli mobli = new Mobli(ID, SECRET);
SampleRequestListener mobliListner = new SampleRequestListener();
runner = new AsyncMobliRunner(mobli);
runner.obtainPublicToken(mobliListner, null);
public class SampleRequestListener extends BaseRequestListner {
public void onComplete(final String response, final Object state) {
try {
// process the response here: executed in background thread
Log.d("Mobli", "Response " + response.toString());
} catch (MobliError e) {
Log.w("Mobli Error", "Error" + e.getMessage());
}
}
}
Any idea what might be wrong with the code?
I have also verified that the URL is formed correctly. I am getting the filenotfoundexcetion in util.java
Turns out there was as an issue in openUrl function in util.java that is a part of mobli sdk. In the openUrl function an extra parameter was being appended to the post request, which was resulting in the above error. Specifically, commenting out the following lines in openUrl function solved the above issue.
// use method override
if (!params.containsKey("method")) {
params.putString("method", method);
}

Android Facebook Open Graph?

I am curious if I can get some help with Open Graph since I can't seem to make any sense out of the Facebook API that I have read.
Right now I have setup my Open Graph Application on Facebook. It has been approved. I am trying to submit my "objects" via the bundle params but I am curious how I setup a bundle param object like the following. Where myObject has multiple values associated with it.
Bundle params = new Bundle();
param.putString("myObject", ""); // My object has multiple values
I guess I really need to figure out how you submit something in the Bundle that has multiple properties associated with it. If anyone has any insight on this please help me out.
At first I had tried something like this.
Bundle myObject = new Bundle();
myObject("property1", "property1Value");
myObject("property2", "property2Value");
myObject("property3", "property3Value");
Bundle params = new Bundle();
params.putString("myObject", myObject);
But in hindsight I figured out why this wouldn't work.
Edit 1
Maybe this will shed some light. Keep in mind this is an Open Graph action which is not a part of the Graph API.
//Build recipe
JSONObject recipe = new JSONObject();
recipe.put("type", "myappns:recipe");
recipe.put("recipe_name", "Thai Island");
recipe.put("cook_time", "1hr. 30min.");
//Build cookbook
JSONObject cookbookParams = new JSONObject();
cookbookParams.put("type", "myappns:book");
cookbookParams.put("title", "Hot & Spicy");
cookbookParams.put("description", "This book consists of hot & spicy foods");
cookbookParams.put("recipes", new JSONArray().put(recipe));
Bundle params = new Bundle();
params.putString("cookbook", cookbookParams.toString());
AsyncFacebookRunner request = new AsyncFacebookRunner(facebook);
request.request("me/myappns:used", params, "POST", new addToTimelineListener(), null);
Here is a question though as I have been digging more into the Open Graph system. I believe I need to actually have a website setup somewhere, is this correct? I was lead to believe through the introductory documentation of Open Graph that I could create and use my Facebook application on Android without the need of any website. That is use the Open Graph system, I know I can use the application to post feeds and what not which I have done successfully.
Thanks again!
Edit 2
Dont even worry about replying I understand what my problem was now...I have to have a website somewhere hosting a Facebook application for the posts to link back too. Makes perfect sense, I haven't seen where the documentation was very direct about this...oh well now I know.
I use this code to publish on wall for multiple object properties.
private void publishPhoto(String imageURL) {
Log.d("FACEBOOK", "Post to Facebook!");
try {
JSONObject attachment = new JSONObject();
attachment.put("message",text);
attachment.put("name", "MyGreatAndroidAppTest");
attachment.put("href", "http://stackoverflow.com/users/909317/sunny");
attachment.put("description","Test Test TEst");
JSONObject media = new JSONObject();
media.put("type", "image");
media.put("src", imageURL);
media.put("href",imageURL);
attachment.put("media", new JSONArray().put(media));
JSONObject properties = new JSONObject();
JSONObject prop1 = new JSONObject();
prop1.put("text", "Text or captionText to Post");
prop1.put("href", imageURL);
properties.put(text, prop1);
// u can make any number of prop object and put on "properties" for ex: //prop2,prop3
attachment.put("properties", properties);
Log.d("FACEBOOK", attachment.toString());
Bundle params = new Bundle();
params.putString("attachment", attachment.toString());
facebook.dialog(MyProjectActivity.this, "stream.publish", params, new DialogListener() {
#Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
#Override
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
#Override
public void onComplete(Bundle values) {
final String postId = values.getString("post_id");
if (postId != null) {
Log.d("FACEBOOK", "Dialog Success! post_id=" + postId);
Toast.makeText(MyProjectActivity.this, "Successfully shared on Facebook!", Toast.LENGTH_LONG).show();
} else {
Log.d("FACEBOOK", "No wall post made");
}
}
#Override
public void onCancel() {
// TODO Auto-generated method stub
}
});
} catch (JSONException e) {
Log.e("FACEBOOK", e.getLocalizedMessage(), e);
}
}
To see a complete example look at the wishlist example.
A complete example for Android is included. The package includes the files to be uploaded on the server and a readme file that explain how to set up all the stuff on the open graph panel.

Can't add comments to photos in Facebook Android application

I am trying to develop a Facebook application for Android. I am unable to integrate the "Add Comment" feature to photos in Facebook Albums. Using the Graph API, I can show the previously made comments on a photo. However, I just can't add new comments to a photo.
Can somebody provide me some helpful advice?
here is simple example on doing that..
// post comment to single photo
Bundle parameters = new Bundle();
String target = "";
target = "<PHOTO_ID>/comments";
parameters.putString("message", "post Comment testing");
mAsyncRunner.request(target, parameters, "POST", new FacebookRequestListener(target+" (post comment)"));
and here is a simple example for the listener (you can get this from examples of facebook-android-sdk too)
public class FacebookRequestListener extends BaseRequestListener {
String caller = "default";
public FacebookRequestListener() {
}
public FacebookRequestListener(String caller) {
this.caller = caller;
}
public void onComplete(final String response) {
try {
Log.d(TAG, "FacebookRequestListener|"+caller+":" + response);
} catch (Exception e) {
Log.w(TAG, "Error:"+e.getMessage());
}
}
}

Categories

Resources