Generate Long-Lived Access Token Facebook Page Access Token

Posted on Updated on

I’ve been working on the new feature for my own blog to auto-posting the posts from the website to the facebook page via Facebook Graph API. My logic was just to make the process automated when I publish new blog post on my website end.

Below, I will cover the processes that are needed on facebook end to collect the required credentials to make the API connectivity successful.

The main credentials needed are, app_id, app_secrect, access_token for my use case.
We can easily get the app_id, app_secrect after creating the app, but to get the long-lived page access token there are some steps to follow.

Facebook gives short-lived, long-lived access tokens. I prefer to generate long-lived access token just to get rid of the expiry date and monitoring effort required for it.

I will cover all the steps we need to follow to get the never expiring page access token.

Steps

1. Sign up for facebook developers channel.

2. Create a Facebook App or use an existing app if you already have one.

3. Copy, App ID, App Secret

4. Now, navigate to Facebook Graph API Explorer, to generate short-lived access token.

a. Firstly, Select an app from Application drop-down.
b. Again, in the next drop-down select “Get user access token”.


c. Once you click on “Get user access token in the drop down” you will see a pop-up window like below. There you will be able to select the permission(scopes) for the user access token.


d. Here for my use case I have only selected “publish pages” and “manager pages” permissions which are needed to create never expiring page access token. If would like to understand more about the scopes visit permissions doc.

Generate user access token by clicking on “Get Access Token” button, this will create short-lived user access token.

5. Now we will need to create a long-lived user access token.

Now, navigate to Access Token Tool this page, you will see short-lived user access token, app access token for all the apps you have under your account.

Press debug option at right side for the user access token for the current app we are trying to create a long-lived access token. This will again take you to Access Token Debugger where you will see the full information for the short-lived user access token.

Short-lived user access token means that will expire after an hour. So to extend the expiry date, we need to go to the bottom, there is an option to generate long-lived(2 months) user access token. Click on “Extend Access Token” and you will get the long-lived access token.

6. Lastly, creating never expiring Access Token.

Again, go to Graph API Explorer and paste the recently created long-lived user access token in the Access Token field.

Now, we need to change the API endpoint to access “/me/accounts” and click on “Submit” button. This process will show the result with all pages information including page access token i.e never expiring token.

7. Finally, we are at the verification step to make sure the page access token is never expiring.

The process I have explained above also works for new version v3.0 of Facebook Graph API

Simple Steps to Fix 403 Forbidden Errors in Wamp Server

Posted on Updated on

Have you recently installed Wamp server? are you getting 403 forbidden error? are you looking for information on how to fix this error quickly? Don’t worry, this article can solve your problem in minutes.

403 forbidden is the most common error being faced by developers while installing WAMP server. If you’re one who just installed Wamp server 2.2 and got this error message “403 Forbidden Error – You don’t have permission to access / on this server.”, don’t panic, you can fix this forbidden error in just 5 minutes by following these 5 simple steps.

  • Open httpd.conf
  • Find text in having Deny from all and replace with Allow from all
  • Also find this code: Order Deny, Allow, Deny from all, Allow from 127.0.0.1 and replace with Order Deny, Allow Deny from all, Allow from all
  • Now restart all services of the wamp server
  • Click on localhost or goto default browser and write localhost and it will start working

Detailed Steps to fix the error:

 Step 1 : Open “httpd.conf” file from below path. C:\wamp\bin\apache\apache2.2.22\conf\httpd.conf (You need to locate your drive where you have installed wamp. In this case, we have installed wamp in C drive) Step 2 : Find this lines from httpd.conf file Options FollowSymLinks AllowOverride None Order deny,allow Deny from all And replace it with Options FollowSymLinks AllowOverride None Order deny,allow Allow from all Step 3 : Also find these code in httpd.conf file Order Deny,Allow Deny from all Allow from 127.0.0.1 And replace it with Order Deny,Allow Deny from all Allow from All Save the file and close it. Step 4 : Wamp restart all services. Step 5 : Start local host AND goto your default web browser and write “Localhost” at URL It's Done !!! 

On Blur Username text disappear

Posted on Updated on

Just add the below code to html tag appear/disappear username text into text box.

 <inpyt type="text" name="username" onfocus="if(this.value =='Username' ) this.value=''" onblur="if(this.value=='') this.value='Username'" value="Username" /> 

AlphaNumeric and Maximum character Validation

Posted on Updated on

The below function will help you for validation of AlphaNumeric and Maximum character Validation.

 function AlphaNumeric(value,name) { re = /^[A-Za-z]+$/; charlegnth = value.length; if((!re.test(value) || (charlegnth &gt; 50))){ alert('It Should be only alphabets and Max 50 characters'); window.setTimeout(function (){ document.getElementById(name).focus(); }, 0); return false; } } 

validation on class name in jQuery Validator

Posted on

 // add method where you want to apply your logic on jquery ready function $.validator.addMethod("greaterThan",	function (value, element, param) {	var section_total_mark_id = (element.id).replace('passing_marks','total_marks');	var section_total_mark = parseInt($('#'+section_total_mark_id).val());	if(parseInt(value) > parseInt(section_total_mark)){	return false;	}else{	return true;	}	}, "Passing Marks must be less than total marks"); ========================================================================================== 2. Add below relus for above method where "section_passing_marks" is your class name. ==========================================================================================	$.validator.addClassRules({	section_passing_marks:{	greaterThan: true	}	}); 

CI file upload function

Posted on Updated on

 public function do_upload_image($id,$field_name) {	$this->load->library('upload');	$files = $_FILES;	$final_array = array();	$cpt = count($_FILES[$field_name]['name']);	//for ($i = 0; $i < $cpt; $i++) {	foreach($files[$field_name]['name'] as $f_key => $fdata){	if($fdata != ''){	if($files[$field_name]['name'][$f_key] != ""){	$_FILES[$field_name]['name'] = $files[$field_name]['name'][$f_key];	$_FILES[$field_name]['type'] = $files[$field_name]['type'][$f_key];	$_FILES[$field_name]['tmp_name'] = $files[$field_name]['tmp_name'][$f_key];	$_FILES[$field_name]['error'] = $files[$field_name]['error'][$f_key];	$_FILES[$field_name]['size'] = $files[$field_name]['size'][$f_key];	// upload an image options	$config = array();	// upload an image options	$dir_name= '';	if($field_name == 'question_image'){	$dir_name = 'question';	}else if($field_name == 'ans_image'){	$dir_name = 'answer';	}	if(!file_exists(FCPATH . 'assets/uploads/Uploads/question_creation/'.$dir_name.'/'.$id))	mkdir(FCPATH . 'assets/uploads/Uploads/question_creation/'.$dir_name.'/'.$id,0777);	$config['upload_path'] = FCPATH . 'assets/uploads/Uploads/question_creation/'.$dir_name.'/'.$id."/";	$config['allowed_types'] = 'jpg|png|jpeg|gif';	$config['max_size'] = '50000000000000000';	$config['overwrite'] = FALSE;	$this->upload->initialize($config);	$file_name = array();	if ($uploads_data = $this->upload->do_upload($field_name)) {	$upload_data = $this->upload->data();	$file_name['name'] = $upload_data['file_name'];	$img = array('image/gif', 'image/jpg', 'image/png', 'image/jpeg');	if (in_array($upload_data['file_type'], $img)) {	$file_name['type'] = 'image';	}	} else {	$file_name[] = $_FILES[$field_name]['error'];	}	$final_array[] = $file_name;	}	}	}	return $final_array; } 

Login Code :

File Upload using Ajax

Posted on Updated on

var param = new FormData(this);
$.ajax({
type: ‘POST’,
url: site_url, // where site_url is website url and method name
data: param,
cache: false,
contentType: false,
processData: false,
success: function (resp) {

var msg;
if(resp == 1) {
msg = ‘data_added_successfully’;
} else if (resp == 0){
msg = ‘data_not_added’;
} else{
msg = ‘please_try_again’;
}
show_message_reload_popup(msg);
}
});

DropBox API integration using php

Posted on Updated on

Hello Guys,

I have guideline to integrate Drop-box API with your PHP application. Click here to get complete demo of Drop box API. Just change the app key and secret key in app-info.json file which is in dropbox-sdk folder.

1+ [Google plus] share script

Posted on Updated on

Hello,

Below code will help you to create share function with Google Plus.

Download the JS file from URL below and attache it in your source file.

http://www.mediafire.com/view/e20vcwd65abysae/plateform.js

Now Put he below code to add Google+ Icon in your page

 <a onclick="javascript:window.open(this.href, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');return false;" href="https://plus.google.com/share?url={URL TO share}"><img alt="Share on Google+">Google Plus</a> 

Tweeter Share Script

Posted on Updated on

Hello Guys,

Below code will help you to put share button on your website. Please add the below HTML code to your html page and change the URL,Via parameter of this code.

 <a title="Share on Twitter" href="javascript:void(0);" rel="nofollow" onclick="window.open('https://twitter.com/share?url=your URL to share&amp;via=Reach&amp;text=This is a book of everyday heroes. It is a collection of men known and unknown','Twitter Dialog','width=626,height=436');return false">