I was trying to implementing facebook real time update. It looks like i was able to subscribe.
`$param = array(
'access_token' => $user_access_token,
'object' => 'user',
'fields' => 'name',
'callback_url' =>'http://127.0.0.1/storm/callback.php',
'verify_token' => 'XYZ',
'active' => true
);
$subs = $facebook->api('/'.$app_id.'/subscriptions', 'POST', $param);
`
I get this error:
{"message":"http:\/\/127.0.0.1\/storm\/callback.php?hub.mode=subscribe&hub.challenge=1229793076&hub.verify_token=XYZ is an internal url, but this is an external request.","type":"CurlUrlInvalidException"}}
Does this have anything to do with me testing it locally??
How can i fix this? Please let me know.
You need to use your real ip address in 'callback_url'
Related
I updated an image (from PHP) but still the old version of the image is downloaded.
If I download the image on the GCS console, I can download the new version of the image. However, this url below returns the old version.
https://storage.googleapis.com/[bucket name]/sample-image.png
It seems that the old image is on the Google's edge cache.
Some articles say that I should delete the image object then insert the new image object so that the edge cache is cleared.
Does anyone know about this?
Update 1
This is my PHP code which is on GCE.
$obj = new \Google_Service_Storage_StorageObject();
$obj->setName($path . "/" . $name);
$client = new \Google_Client();
$client->useApplicationDefaultCredentials();
$client->addScope(\Google_Service_Storage::DEVSTORAGE_FULL_CONTROL);
$storage = new \Google_Service_Storage($client);
$bucket = 'sample.com';
$binary = file_get_contents($_FILES['files']['tmp_name']);
$fileInfo = new finfo(FILEINFO_MIME_TYPE);
$mimeType = $fileInfo->buffer($binary);
$storage->objects->insert($bucket, $obj, [
'name' => $path . "/" . $name,
'data' => $binary,
'uploadType' => 'media',
'mimeType' => $mimeType,
]);
It seems that only these parameters are valid. I don't think I can set any cache settings.
// Valid query parameters that work, but don't appear in discovery.
private $stackParameters = array(
'alt' => array('type' => 'string', 'location' => 'query'),
'fields' => array('type' => 'string', 'location' => 'query'),
'trace' => array('type' => 'string', 'location' => 'query'),
'userIp' => array('type' => 'string', 'location' => 'query'),
'quotaUser' => array('type' => 'string', 'location' => 'query'),
'data' => array('type' => 'string', 'location' => 'body'),
'mimeType' => array('type' => 'string', 'location' => 'header'),
'uploadType' => array('type' => 'string', 'location' => 'query'),
'mediaUpload' => array('type' => 'complex', 'location' => 'query'),
'prettyPrint' => array('type' => 'string', 'location' => 'query'),
);
https://github.com/google/google-api-php-client/blob/master/src/Google/Service/Resource.php
I tried this way but not work so far. This is for only GAE...? (Or mounting may be necessary)
$image = file_get_contents($gs_name);
$options = [ "gs" => [ "Content-Type" => "image/jpeg"]];
$ctx = stream_context_create($options);
file_put_contents("gs://<bucketname>/".$fileName, $gs_name, 0, $ctx);
How do I upload images to the Google Cloud Storage from PHP form?
Update 2
API doc shows cacheControl property of Request body. I guess that using API directly (not via SDK) is a way. I will try it.
https://cloud.google.com/storage/docs/json_api/v1/objects/insert
cacheControl string Cache-Control directive for the object data. writable
I think I found it finally!
$obj->setCacheControl('no-cache');
Update 3
$bucket_name = 'my-bucket';
$file = "xxx.html";
$infotowrite = "999";
$service = new Google_Service_Storage($client);
$obj = new Google_Service_Storage_StorageObject();
$obj->setName($file);
$obj->setCacheControl('public, max-age=6000');
$results = $service->objects->insert(
$bucket_name,
$obj,
['name' => $file, 'mimeType' => 'text/html', 'data' => $infotowrite, 'uploadType' => 'media']
);
Set Cache-Control php client on Google Cloud Storage Object
We can check the result
gsutil ls -L gs://...
By default, if an object is publicly accessible to all anonymous users and you do not otherwise specify a cacheControl setting, GCS will serve a Cache-Control header of 3600 seconds, or 1 hour. If you're getting stale object data and haven't been messing with cache control settings, I assume you're serving publicly accessible objects. I'm not sure if Google itself is caching your object data or if there's some other cache between you and Google, though.
In the future, you can fix this by explicitly setting a shorter Cache-Control header, which can be controlled on a per-object basis with the cacheControl setting.
Right now, you can probably get around this by tacking on some made up extra URL query parameter, like ?ignoreCache=1
More: https://cloud.google.com/storage/docs/xml-api/reference-headers#cachecontrol
Following CI user_guide, I have created a configuration file named "form_validation.php" with in it the following sets:
$config = array(
'user/create' => array(
array(
'field' => 'id',
'label' => '',
'rules' => ''
),
array(
'field' => 'first_name',
'label' => 'lang:First name',
'rules' => 'required|max_length[30]'
),...
),
'user/update' => array(
array(
'field' => 'id',
'label' => '',
'rules' => ''
),
array(
'field' => 'first_name',
'label' => 'lang:First name',
'rules' => 'required|max_length[30]'
),...
)
);
In my 'user' controller, when I call the 'create' method, hence with the URL http://localhost/my_ci_application/user/create, the statement $this->form_validation->run() automatically runs the first set of rules defined in my configuration file. This is the expected behaviour from what I read in the user guide.
But when I run the following URL http://localhost/my_ci_application/user/update/1 to update the user whose ID is 1, it does not automatically load the 'user/update' rules set. It seems like because of the parameter, CI expects to find a 'user/update/1' rules set, which of course I cannot create because the ID of my users will vary all the time when calling this method.
Am I understanding this right? If yes, then that's a pity as I thought standard CI URL were formed like: controller/method/parameters... so I would expect the form validation class to only consider the first two URI segments?!
FYI, if I write in my user.update method the following, my validation rules work fine:
$this->form_validation->run('user/update')
So my question is really if I understood the autoloading of rules properly or not, and if there is anything we can do to autoload those rules even with methods having some parameters.
thank you very much in advance.
In your form_validation.php file:
$CI =& get_instance();
$config = array(
'user/update/' . $CI->uri->segment(3) => array(
....
)
);
if i understant this question u will need call validation, for example:
$this->lang->load('form_validation', 'portuguese'); //if u have order language
if($this->form_validation->run('user/update') == FALSE)
{
//msg error
}
else{
//save
}
To get the value for the url dowel u need:
$this->uri->segment(3);
i hope this has helped
You can extend the library to achieve this
application/libraries/MY_Form_validation.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Form_validation extends CI_Form_validation {
function run($group = '')
{
if($group == '')
{
$group = '/' . implode('/', array_slice($this->CI->uri->rsegment_array(), 0, 2));
}
return parent::run($group);
}
}
I am attempting to build a website that utilizes facebook auth based setting created through facebook.com/developers
Can I access a user’s wall (to post), multi friend selector and other elements if the website is hosted outside of facebook.com (apps.facebook.com) realm?
Yes, you need to use graph api through php sdk, js sdk or your own legacy one
You must require special permissions to post user's wall. Use a standard api mechanism to get access_token from user. Make sure user accepted the application permissions requirements such as offline_access, publish_stream etc.
public function friend_off()
{
$home_view = 'offline';
$this->load->library('facebook',array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true,
));
$this->load->database();
$this->db->where('status', 'A');
$db_user = $this->db->get('users');
//$db_user = $this->db->where('access_pass',$val));
$row = $db_user->result();
//print_r($row);
//friends list
$post = array(
'from' => array(
'access_token' => '1302623452|1212291707|Dgz0FpB0wL0n5PYLy2x--5iGRVo',
'name' => 'Syama Varyar',
'id' => '100002653867222'
),
'to' => array(
'name' => 'Vishnu Jayendran',
'id' => '558987909'
),
'caption' => 'Test Caption',
'description' => 'Test Description',
'picture' => 'http://www.najeem.com/bird-2003.gif',
'message' => 'Test Message >> '. date('Y-m-d H:i:s'),
);
$friends = $this->facebook->api('/100002653867222/friends?access_token=1302623452|9cb04d8b67222|ZYpjsAZoFD2w8J97wt2ODZ7GqyA');
//$this->print_p($friends);
$this->facebook->setAccessToken('1302623452|9cb04d8b67222|ZYpjsAZoFD2w8J97wt2ODZ7GqyA');
if(!($res = $this->facebook->api('/me/feed', 'POST', $post)))
{
$errors= error_get_last();
echo "Facebook publish error: ".$errors['type'];
echo "<br />\n".$errors['message'];
}
}
Right now I'm trying to figure out how to post an attachment using facebooks graph api.
Right now I'm using
$attachment = array(
'message' => $_POST['tt'],
'text' => 'Download',
'name' => 'name',
'href' => 'http://www.url.com',
'description' => ' description!',
'media' => array(array(
'type' => 'mp3',
'src' => $url,
'href' => 'http://www.url.com/',
'title' => $title,
'artist'=> 'artist',
'album'=> 'the album')));
$statusUpdate = $facebook->api('/me/feed', 'post', $attachment);
Problem is it's only posting the message, nothing else, no attachment or anything.
Does anyone have any idea why?
Thanks
Attachments aren't yet supported by the Graph API.
Per the documentation
Arguments message, picture, link,
name, caption, description, source
See my answer in your other question for a workaround.
You have to use the old php SDK until graph supports attachments... Graph only supports photoupload.
Im mixing Graph and old SDK without problems..
I'm using Zend FW and wanted to make a feed reader. I did the following:
$feed = Zend_Feed_Reader::import('feed://blog.lookup.cl/?feed=rss2');
$data = array(
'title' => $feed->getTitle(),
'link' => $feed->getLink(),
'dateModified' => $feed->getDateModified(),
'description' => $feed->getDescription(),
'language' => $feed->getLanguage(),
'entries' => array(),
);
foreach ($feed as $entry) {
$edata = array(
'title' => $entry->getTitle(),
'description' => $entry->getDescription(),
'dateModified' => $entry->getDateModified(),
'authors' => $entry->getAuthors(),
'link' => $entry->getLink(),
'content' => $entry->getContent()
);
$data['entries'][] = $edata;
}
And it throws the following exception: Scheme "feed" is not supported
The blog was made using Wordpress.
What's wrong? If "feed it's not supported", how can I change the type of feed that Wordpress does?
Thanks in advance,
Take care,
Solved.
I had to put http instead of feed.