我在Android中使用Facebook创建了邀请用户到应用程序,对于这个使用过的Facebook SDK并添加了由其他人提供的代码,这里是我的代码
final ImageView facebook1 = (ImageView) findViewById(R.id.facebook1);
facebook1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
// Perform action on click
Facebook facebook1 = new Facebook("APP_ID");
Bundle paramsOut = new Bundle(), paramsIn = this.getIntent().getExtras();
paramsOut.putString("message", paramsIn.getString("message"));
Singlemenuitem.this.mFacebook.dialog(this, "apprequests", paramsOut, new InviteListener(this));
mFacebook.dialog(Singlemenuitem.this, "apprequests", params, new DialogListener() {
public void onComplete(Bundle values) {
final String returnId = values.getString("request");
if (returnId != null) {
Toast.makeText(getApplicationContext(),
"Request sent " + returnId,
Toast.LENGTH_SHORT).show();
}
}
public void onFacebookError(FacebookError error) {}
public void onError(DialogError e) {}
public void onCancel() {}
});
}
但代替“InviteListener”获取创建类的错误,如果创建了类,那么也会收到错误。任何指导?
答案 0 :(得分:0)
Bundle iviteBundleparams = new Bundle();
iviteBundleparams.putString("message",
"invite message");
//TODO:// if you have friend id then you can pass friend id and the request will send this particular friend id
//myIviteBundleparams.putString("to",
friendId);
final ImageView facebook1 = (ImageView) findViewById(R.id.facebook1);
facebook1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
mFacebook.dialog(context,
"apprequests", iviteBundleparams,
new AppRequestsListener());
}
} catch (Exception e) {
// Log.e("VIAMO_FRIENDS", "" + e.toString());
e.printStackTrace();
}
}
});
/*
* callback for the apprequests dialog which sends an app request to user's
* friends.
*/
public class AppRequestsListener extends BaseDialogListener {
/* Default constructor definition */
public AppRequestsListener() {
// TODO Auto-generated constructor stub
}
public void onComplete(Bundle values) {
if (values.size() < 1) {
Toast toast = Toast.makeText(getApplicationContext(),
"App request cancelled", Toast.LENGTH_SHORT);
toast.show();
} else {
Toast toast = Toast.makeText(getApplicationContext(),
"App request sent", Toast.LENGTH_LONG);
toast.show();
}
}
public void onFacebookError(FacebookError error) {
Toast.makeText(getApplicationContext(),
"Facebook Error: " + error.getMessage(), Toast.LENGTH_SHORT)
.show();
}
public void onCancel() {
Toast toast = Toast.makeText(getApplicationContext(),
"App request cancelled", Toast.LENGTH_SHORT);
toast.show();
}
}
//这里mFacebook是你的Facebook对象 // Facebook mFacebook =新Facebook(APP_ID);