Showing posts with label Facebook. Show all posts
Showing posts with label Facebook. Show all posts

Getting AccessToken Using App id, App Secret Key of facebook app

Getting AccessToken  Using App id, App Secret Key of facebook app

use the url 

 https://graph.facebook.com/oauth/access_token? type=client_cred&client_id="+appId+"&client_secret="+appSecret


Sample Code:
 public static String getAccessToken() {


  InputStream is = null;

  String result = "";
  String url;
  String urlParameters = null;
  
  try {
   url = "https://graph.facebook.com/oauth/access_token?type=client_cred&client_id="+appId+"&client_secret="+appSecret;
   
   System.out.println("url is "+url);

   HttpClient httpclient = new DefaultHttpClient();
   HttpPost httppost = new HttpPost(url);
   HttpResponse response = httpclient.execute(httppost);
   HttpEntity entity = response.getEntity();
   is = entity.getContent();
  } catch (Exception e) {
   Log.e("log_tag", "Error in http connection " + e.toString());
  }
  // convert response to string
  try {

   BufferedReader reader = new BufferedReader(new InputStreamReader(
     is, "iso-8859-1"), 8);
   StringBuilder sb = new StringBuilder();
   String line = null;
   while ((line = reader.readLine()) != null) {
    sb.append(line + "\n");
   }
   is.close();

   result = sb.toString();

  } catch (Exception e) {
   Log.e("log_tag", "Error converting result " + e.toString());

  }

  return result;

 }

Facebook Fan Page Feeds in Android

Facebook Fan Page Feeds in Android

No Need for Appid,App scrt key etc...

For getting public fan page feed ,use the url 



 https://www.facebook.com/feeds/page.php?id=PAGE_ID&format=json


Sample Code:
public class MainActivity extends Activity {

 String pageId ="xxxxxxxxxxxx";
 InputStream is;
 String result;
 String finalPara;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
      
      
        try {
   
         String feed = "https://www.facebook.com/feeds/page.php?id="+pageId+"&format=json";
    
   HttpClient httpclient = new DefaultHttpClient();
   HttpPost httppost = new HttpPost(feed);
       HttpResponse response = httpclient.execute(httppost);
   HttpEntity entity = response.getEntity();
   is = entity.getContent();
  } catch (Exception e) {
   Log.e("log_tag", "Error in http connection " + e.toString());
  }
  // convert response to string
  try {

    BufferedReader reader = new BufferedReader(new InputStreamReader(
     is, "iso-8859-1"), 8);
   StringBuilder sb = new StringBuilder();
   String line = null;
   while ((line = reader.readLine()) != null) {
    sb.append(line + "\n");
   }
   is.close();

   result = sb.toString();
   
   System.out.println("feed details "+result);

  } catch (Exception e) {
   Log.e("log_tag", "Error converting result " + e.toString());

  }
        
    }

  

    


FaceBook Image Share in android


//After login,



public void login() {
facebook.authorize(
FaceBookAuthentication.this,
new String[] { "user_photos,publish_checkins,publish_actions,publish_stream" },
new DialogListener() {

public void onFacebookError(FacebookError e) {
showToast("Authentication with Facebook failed!");
finish();

}

public void onError(DialogError e) {
showToast("Authentication with Facebook failed!");
finish();

}

public void onComplete(Bundle values) {
postImage();
Toast.makeText(getApplicationContext(),
"Image Successfully Posted on Facebook.",
Toast.LENGTH_SHORT).show();

Intent i = new Intent(FaceBookAuthentication.this,
HairMagic.class);
startActivity(i);

}

public void onCancel() {
showToast("Authentication with Facebook cancelled!");
finish();

}
});


public void postImage() {
byte[] data = null;

Bundle params = new Bundle();
params.putString(Facebook.TOKEN, facebook.getAccessToken());
params.putString("method", "photos.upload");
params.putByteArray("picture", imageName.bytearray);
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request(null, params, "POST", new SampleUploadListener(),
null);

}
 

Popular Posts

About Me

Only For Sharing Android Related Things...

Facebook Fan Page