コード例 #1
0
function engage_parse_result($result, $format, $array_out = ENGAGE_PARSE_ARRAY)
{
    if ($array_out === true) {
        $array = true;
    } else {
        $array = false;
    }
    $ready = true;
    if ($result === false) {
        $ready = false;
    }
    if (!in_array($format, explode(',', ENGAGE_FORMATS))) {
        $ready = false;
    }
    if ($ready === true) {
        if ($format == ENGAGE_FORMAT_JSON) {
            $decode_result = json_decode($result, $array);
            if ($decode_result === NULL) {
                switch (json_last_error()) {
                    case JSON_ERROR_DEPTH:
                        $json_error = ENGAGE_JERROR_DEPTH;
                        break;
                    case JSON_ERROR_UTF8:
                    case JSON_ERROR_CTRL_CHAR:
                        $json_error = ENGAGE_JERROR_CHAR;
                        break;
                    case JSON_ERROR_SYNTAX:
                    case JSON_ERROR_STATE_MISMATCH:
                        $json_error = ENGAGE_JERROR_SYN;
                        break;
                }
                engage_error(ENGAGE_JSON_ERROR . $json_error);
                return false;
            }
        } elseif ($format == ENGAGE_FORMAT_XML) {
            $xmlconfig = libxml_use_internal_errors(true);
            $decode_result = simplexml_load_string($result);
            if ($decode_result === false) {
                $xml_errors = libxml_get_errors();
                foreach ($xml_errors as $xml_error) {
                    engage_error(ENGAGE_XML_ERROR . $xml_error->code);
                }
                libxml_clear_errors();
                return false;
            }
            if ($array === true) {
                $decode_result = json_encode($decode_result);
                $decode_result = engage_parse_result($decode_result, ENGAGE_FORMAT_JSON, true);
            }
        }
        return $decode_result;
    }
    return false;
}
コード例 #2
0
/**
 * http://documentation.janrain.com/activity
 * To use activity requires a subscription level of Pro or better.
 *
 * You must setup the provider(s) for sharing on the Engage dashboard.
 * (rpxnow.com - Deployment - Configure Providers)
 *
 * The following fields are only used by Facebook and are ignored by other providers:
 * title, description, action_links, media, properties
 *
 * Read more about the Facebook extras at the URL below.
 * http://developers.facebook.com/docs/guides/attachments
 *
 * If more than one media type is included the "media" array Facebook will 
 * choose only one of these types. This is the order Facebook will use to select: 
 * image, flash, mp3 (a.k.a. music)
 */
function engage_activity($api_key, $identifier, $activity, $location = NULL, $truncate = ENGAGE_TRUNCATE, $url_shortening = ENGAGE_URLSHORT, $prepend_name = ENGAGE_PRENAME)
{
    $ready = true;
    if (strlen($api_key) != ENGAGE_API_KEY_LEN) {
        engage_error(ENGAGE_ERROR_APIKEY, __FUNCTION__);
        $ready = false;
    }
    if (empty($identifier)) {
        engage_error(ENGAGE_ERROR_IDENT, __FUNCTION__);
        $ready = false;
    }
    if (!is_array($activity)) {
        engage_error(ENGAGE_ERROR_ARRAY, __FUNCTION__);
        $ready = false;
    }
    if ($ready === true) {
        $url = ENGAGE_API_BASE_URL . ENGAGE_ACTIVITY_EP;
        $activity = json_encode($activity);
        $parameters = array(ENGAGE_KEY_APIKEY => $api_key, ENGAGE_KEY_IDENTIFIER => $identifier, ENGAGE_KEY_ACTIVITY => $activity, ENGAGE_KEY_TRUNCATE => $truncate, ENGAGE_KEY_URLSHORT => $url_shortening, ENGAGE_KEY_PRENAME => $prepend_name);
        if ($location !== NULL) {
            $parameters[ENGAGE_KEY_LOCATION] = $location;
        }
        $result = engage_post($url, $parameters);
        if ($result !== false) {
            $response = engage_parse_result($result);
            if (is_array($response)) {
                if ($response[ENGAGE_KEY_STAT] != ENGAGE_STAT_OK) {
                    engage_error(ENGAGE_ERROR_STAT . $result, __FUNCTION__);
                    return false;
                }
            }
        }
        return $result;
    }
    return false;
}
コード例 #3
0
 */
require_once 'engage-conf.php';
//<- Set your API KEY in the variable $api_key in this file.
$identifier = urldecode($_GET['identifier']);
// Get the identifier from the HTTP query.
$format = ENGAGE_FORMAT_JSON;
$result = engage_get_contacts($api_key, $identifier);
if ($result === false) {
    $errors = engage_get_errors();
    foreach ($errors as $error => $label) {
        $debug_array[] = 'Error: ' . $error;
    }
} else {
    $array_out = true;
    /* On a successful get_contacts the variable (array) $get_contacts_array will contain the resulting data. */
    $get_contacts_array = engage_parse_result($result, $format, $array_out);
    $debug_array[] = print_r($get_contacts_array, true);
}
/*
 * Uncomment lines below to get SDK level
 * debug data. Caution: This could result in 
 * revealing the api_key.
 */
//$debugs = engage_get_errors(ENGAGE_ELABEL_DEBUG);
//foreach ($debugs as $debug=>$label) {
//	$debug_array[] = 'Debug: '.$debug;
//}
$the_buffer = ob_get_contents();
if (!empty($the_buffer)) {
    $debug_array[] = 'Buffer: ' . $the_buffer;
}
コード例 #4
0
ファイル: index.php プロジェクト: ahliana/Janrain-Sample-Code
$format = ENGAGE_FORMAT_JSON;
$extended = $auth_info_extended;
$result = engage_auth_info($api_key, $token, $format, $extended);
if ($result === false) {
    $errors = engage_get_errors();
    foreach ($errors as $error => $label) {
        $debug_array[] = 'Error: ' . $error;
    }
} else {
    /**
     * On a successful authentication store
     * the auth_info data in the variable
     * $auth_info_array
     */
    $array_out = true;
    $auth_info_array = engage_parse_result($result, $format, $array_out);
    //Put a printed copy in the debug.
    $debug_array[] = print_r($auth_info_array, true);
    /**
     * This is the point to add code to do something with the Engage data.
     */
}
$errors = engage_get_errors(ENGAGE_ELABEL_ERROR);
foreach ($errors as $error => $label) {
    $error_array[] = 'Error: ' . $error;
}
/*
 * Uncomment lines below to get SDK level
 * debug data. Caution: This could result in 
 * revealing the api_key.
 */
コード例 #5
0
ファイル: index.php プロジェクト: ahliana/Janrain-Sample-Code
     }
     $result = engage_auth_info($vals['api_key'], $vals['token'], $vals['format'], $extended);
     if ($result === false) {
         $clean = false;
     } else {
         $actions['parse_result'] = array('result' => $result, 'format' => $vals['format'], 'export' => array('identifier' => array('profile', 'identifier')), 'do' => true);
         if ($vals['format'] == 'json') {
             $actions['indent_json'] = array('json' => $result, 'do' => true);
         }
         if ($vals['format'] == 'xml') {
             $actions['indent_xml'] = array('xml' => $result, 'do' => true);
         }
     }
     break;
 case 'parse_result':
     $parse_result = engage_parse_result($vals['result'], $vals['format']);
     if ($parse_result === false) {
         $clean = false;
     } else {
         if (is_array($parse_result)) {
             if (isset($parse_result['err'])) {
                 $engage_error = true;
             } elseif (is_array($vals['export'])) {
                 foreach ($vals['export'] as $export_name => $export_path) {
                     $export_val = '';
                     foreach ($export_path as $e_key => $e_path) {
                         if (empty($export_path)) {
                             $export_val = $parse_result["{$e_path}"];
                         } else {
                             $export_val = $export_val["{$e_path}"];
                         }