Skip to content

Instantly share code, notes, and snippets.

View niraj-shah's full-sized avatar
🏠
Working from home

Niraj Shah niraj-shah

🏠
Working from home
View GitHub Profile
@niraj-shah
niraj-shah / page_post.php
Last active May 16, 2023 10:32
Posting to a Page using Facebook PHP SDK v4.0.x and Graph API v2.x
<?php
// post to page
$page_post = (new FacebookRequest( $session, 'POST', '/'. $page_id .'/feed', array(
'access_token' => $access_token,
'name' => 'Facebook API: Posting As A Page using Graph API v2.x and PHP SDK 4.0.x',
'link' => 'https://www.webniraj.com/2014/08/23/facebook-api-posting-as-a-page-using-graph-api-v2-x-and-php-sdk-4-0-x/',
'caption' => 'The Facebook API lets you post to Pages you administrate via the API. This tutorial shows you how to achieve this using the Facebook PHP SDK v4.0.x and Graph API 2.x.',
'message' => 'Check out my new blog post!',
) ))->execute()->getGraphObject()->asArray();
@niraj-shah
niraj-shah / page_token.php
Created August 23, 2014 12:56
Get Page Access Token for a given Facebook Page. Using Facebook PHP SDK 4.0.x.
<?php
// get page access token
$access_token = (new FacebookRequest( $session, 'GET', '/' . $page_id, array( 'fields' => 'access_token' ) ))
->execute()->getGraphObject()->asArray();
// save access token in variable for later use
$access_token = $access_token['access_token'];
@niraj-shah
niraj-shah / like_fb4.0.x.php
Created August 18, 2014 09:21
Checking if a user has liked a specific page using Facebook PHP SDK 4.0.x and Graph API 2.0+
<?php
// get like status
$liked = (new FacebookRequest( $session, 'GET', '/me/likes/' . $page_id ))->execute()->getGraphObject()->asArray();
// if $liked return array with at least one result, user has liked the page
if ( isset( $liked ) && count( $liked ) > 0 ) {
echo '<h2>Liked</h2>';
} else {
echo '<h2>Not Liked</h2>';
@niraj-shah
niraj-shah / pagination.php
Created August 12, 2014 12:00
Parse Pagination Using Unofficial PHP Parse SDK from: https://github.com/apotropaic/parse.com-php-library
<?php
// using https://github.com/apotropaic/parse.com-php-library PHP Parse Library
require_once( 'Parse/parse.php' );
$query = new parseQuery('TestClass');
// hack to get all results
$query->whereNotEqualTo( 'name', 'foo' );
@niraj-shah
niraj-shah / map.html
Last active August 29, 2015 14:05
Cage Cricket "Where to Play" Map Embed Code
<div id="cc-map"></div>
<!-- uses latest version of jQuery (v2.1.1) -->
<script src="http://www.cagecricket.com/wp-content/plugins/cage-cricket/map-embed.php"></script>
<!-- jQuery-less version -->
<script src="http://www.cagecricket.com/wp-content/plugins/cage-cricket/map-embed.php?jquery=false"></script>
@niraj-shah
niraj-shah / find_php.sh
Created August 7, 2014 12:45
Find PHP and .DS_Store files in current directory
# Find PHP files in current directory
find . -name *.php -exec echo {} \;
# Find annoying .DS_Store files in current directory (Mac issue)
find . -name .DS_Store -exec echo {} \;
# Find log files in current directory (ending in.log)
find . -name *.log -exec echo {} \;
@niraj-shah
niraj-shah / find_and_delete.sh
Last active August 29, 2015 14:05
Find and delete .svn / .git subdirectories in a given folder
# === SVN === #
# find .svn folders in current directory
find . -name .svn -exec echo {} \;
# delete .svn folders in current directory
find . -name .svn -exec rm -rfv {} \;
# === GIT === #
@niraj-shah
niraj-shah / parse.php
Last active August 29, 2015 14:04
Using the official Parse PHP SDK v1.0
<?php
// define location of Parse PHP SDK, e.g. location in "Parse" folder
// Defaults to ./Parse/ folder. Add trailing slash
define( 'PARSE_SDK_DIR', './Parse/' );
// include Parse SDK autoloader
require_once( 'autoload.php' );
// Add the "use" declarations where you'll be using the classes
@niraj-shah
niraj-shah / autoload.php
Last active August 29, 2015 14:04
Autoloader for Official Parse PHP SDK
<?php
/**
* You only need this file if you are not using composer.
* Adapted from the Facebook PHP SDK 4.0.x autoloader
*/
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
throw new Exception('The Parse SDK requires PHP version 5.4 or higher.');
}
@niraj-shah
niraj-shah / parse-acl.js
Created July 3, 2014 13:13
Parse.com JavaScript SDK - ACL Examples
// true = access allowed, false = not allowed
// create ACL
var acl = new Parse.ACL();
// public can read
acl.setPublicReadAccess( true );
// public cannot write
acl.setPublicWriteAccess( false );
// user can read data