以下是我创建facebook事件的代码,但是这段代码不起作用,没有编译或运行时错误。我编写了方法并在按钮点击事件上调用了方法。
public class createEvent extends Activity implements OnClickListener
{
private Button btnCreateEven;
private TextView txteventName;
private AsyncFacebookRunner mAsyncRunner;
private String eventID="";
private Facebook facebookatEventCreate;
private String eventName = "";
private SharedPreferences mPrefs;
private static String appId = "392736034134808";
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.create_event);
//problem - unable to start activity when setListeners() is uncommented
initialize();
setListeners();
}
private void initialize()
{
//facebook = new Facebook(APP_ID);
facebookatEventCreate = new Facebook(appId);
mAsyncRunner = new AsyncFacebookRunner(facebookatEventCreate);
btnCreateEven = (Button) findViewById(R.id.btn_createEvent);
txteventName = (TextView)findViewById(R.id.txt_eventName);
}
private void setListeners()
{
btnCreateEven.setOnClickListener(this);
}
@Override
public void onClick(View v)
{
switch (v.getId())
{
case R.id.btn_createEvent:
createEvents();
default:
break;
}
}
/**
* Creates a new event.
*
*
*
*/
private void createEvents()
{
try
{
Bundle params = new Bundle();
params.putString("name", "test test test");
params.putString("start_time", "2013-12-02T18:00:00+0530");
params.putString("end_time", "2013-12-02T20:00:00+0530");
params.putString("description", "This is test description 10/12/2012");
params.putString("location", "Mount Lavinia");
//params.putString("location_id", "");
params.putString("privacy_type", "OPEN");
params.putString("picture", "/sdcard/cmd.png");
mAsyncRunner.request("me/events", params, "POST", new RequestListener()
{
@Override
public void onMalformedURLException(MalformedURLException e, Object state)
{
}
@Override
public void onIOException(IOException e, Object state)
{
}
@Override
public void onFileNotFoundException(FileNotFoundException e, Object state)
{
}
@Override
public void onFacebookError(FacebookError e, Object state)
{
}
@Override
public void onComplete(String response, Object state)
{
try
{
JSONObject event = new JSONObject(response);
eventID = event.getString("id");
Log.d("createEvent:createEvent", "Event ID->" + eventID);
//Toast.makeText(getApplicationContext(), "New Event Created!!", Toast.LENGTH_LONG).show();
}
catch (Exception e)
{
}
}
}, null);
}
catch (Exception e)
{
}
}
}
请告诉我原因,欢迎提出任何意见!
答案 0 :(得分:0)
我没有看到您在任何地方对用户进行身份验证。您可以在此处了解如何执行此操作:Facebook Authentication for Android
如果您已经对用户进行了身份验证,则需要在创建新的Facebook对象时保存身份验证令牌。您可以使用以下方式读取访问令牌:
facebookatEventCreate.setAccessToken(authToken);
facebookatEventCreate.setAccessExpires(unixTime);