Java tutorial
/* * Copyright 2010 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.autburst.picture.facebook; import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; import org.json.JSONObject; import android.content.Intent; import android.os.Bundle; import android.util.Log; import com.facebook.android.AsyncFacebookRunner; import com.facebook.android.Facebook; import com.facebook.android.FacebookError; /** * Publishes Message to Wall * @author Michael Greifeneder */ public class PublishHandler extends Handler { private static final String TAG = PublishHandler.class.getName(); public void go() { Facebook fb = Session.restore(getActivity()).getFb(); AsyncFacebookRunner runner = new AsyncFacebookRunner(fb); Bundle params = new Bundle(); final Intent intent = getActivity().getIntent(); String message = intent.getStringExtra("message"); String link = intent.getStringExtra("link"); String name = intent.getStringExtra("name"); String caption = intent.getStringExtra("caption"); String description = intent.getStringExtra("description"); String picture = intent.getStringExtra("picture"); params.putString("message", message); params.putString("link", link); params.putString("name", name); params.putString("caption", caption); params.putString("description", description); params.putString("picture", picture); runner.request("me/feed", params, "POST", new AsyncRequestListener() { public void onComplete(JSONObject obj) { String html; Log.d(TAG, "onComplete"); getActivity().runOnUiThread(new Runnable() { @Override public void run() { getActivity().showDialog(FacebookActivity.POSTED); } }); } @Override public void onFacebookError(FacebookError e) { showProblem(); } @Override public void onFileNotFoundException(FileNotFoundException e) { showProblem(); } @Override public void onIOException(IOException e) { showProblem(); } @Override public void onMalformedURLException(MalformedURLException e) { showProblem(); } }); } private void showProblem() { getActivity().showDialog(FacebookActivity.PROBLEM); } }