In my code I can get Facebook to show up, show the requested permissions and authorize, everytime I return after it remembers who I am.
In my app itself though it can not seem to recognize that it is logged in, the call to Authorize never returns through the DialogListener interface. The somewhat incomplete code of my apps adapter is included.
package com.metalrain.ca.newschoolshooter_full;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import Hammer.App.MyLibs.APPSTATICS;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import com.facebook.android.AsyncFacebookRunner;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.FacebookError;
import com.facebook.android.Facebook.DialogListener;
public class FacebookIntegrator implements DialogListener{
public static final String APP_ID = "176680882361390";
private final Facebook mFacebook;
//private final AsyncFacebookRunner mAsyncRunnoner;
Context ctx;
String[] Permissions = new String[] {"publish_stream", "read_stream", "offline_access"};
FacebookIntegrator(final Context ctx) {
this.ctx = ctx;
this.mFacebook = new Facebook(FacebookIntegrator.APP_ID);
//this.mAsyncRunner = new AsyncFacebookRunner(this.mFacebook)开发者_JS百科;
}
public void SubmitScore() {
Log.e("MetalRain", "Started SubmitScore"+mFacebook.getAccessToken());
//I use the class from the login button to do this
//final LoginButton lb = new LoginButton(this.ctx);
if (mFacebook.isSessionValid()) {
Log.i("MetalRain", "There is a valid facebook sessi");
Bundle b = new Bundle();
try {
mFacebook.request("/me/feed", b, "POST");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
b.putString("status", "This is a test: name");
} else {
Log.i("MetalRain","Authorizing facebook");
mFacebook.authorize((Activity) this.ctx,this.Permissions,
this);
}
Log.e("MetalRain", "Finished SubmitScore");
}
public void onComplete(Bundle values) {
if (!values.containsKey("post_id"))
{
try
{
Bundle parameters = new Bundle();
parameters.putString("message", "this is a test");// the message to post to the wall
mFacebook.dialog(APPSTATICS.CTX, "stream.publish", parameters, this);// "stream.publish" is an API call
}
catch (Exception e)
{
// TODO: handle exception
System.out.println(e.getMessage());
}
}
Log.e("MetalRain", "On Complete");
}
public void onFacebookError(FacebookError error) {
Log.e("MetalRain","fbFAILURE "+error.getMessage());
}
public void onError(DialogError error) {
Log.e("MetalRain","FAILURE "+error.getMessage());
}
public void onCancel() {
Log.e("MetalRain","CANCELED");
}
}
I am not seeing any errors or any log messages post-return. It just returns to my activity and acts as if nothing is happening.
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
fbi.mFacebook.authorizeCallback(requestCode, resultCode, data);
}
This was required by the newest version, since it was a fully activity and not some form of remote dialog. Once I added this it all worked (added to my Activity, not the code above, fbi is FacebookIntegrator, the class linked above).
精彩评论