Feasibility: Auto-tweet on Update of a page - php

On my company's website we have a display of 40 100px X 100px images that represent the projects that we have been involved in. We have more like 150 projects, but only 40 are displayed on the homepage and the selection of the 40 is random. See Example Here.
We also have an Update page which sorts these 40 projects by the date they were added. See Here.
In both cases the data is pulled from a PHP MySQL database and displayed as so on the website.
We are hoping to get a twitter presence as well as re-developing our website and I was wondering:
Is there a way to link twitter to the update page, so when I add a new project to the database, or update an existing project it automatically tweets about the new project?
Thanks in advance

It's definitely possible to do; however, since twitter turned off Basic Auth, you'll need to setup a twitter 'app' that you'll grant access to (oAuth) then use that to post. It adds a bit of complexity, but it shouldn't stop you.
Of course, if your CMS can provide an RSS feed of updates/additions (perhaps based on that update page), you could use one of the many RSS to Twitter posting services.
I'm a big fan of the way you can pick and chose Zend Framework's components, so I'd probably use Zend_Service_Twitter for something like this; however, the concept is similar on any Twitter library (or even just interfacing directly with Twitter, but that seems like unnecessary work).
First - as mentioned - you'll need tosetup an app on Twitter. The developer site should help there. You'll also need to **grant your new app access to the account you'll be posting to, what you need is an oAuth access token.
The access token is used for read/write, you'll use it to setup the Twitter library (again, an example from Zend's documentation, but it should be similar to other libraries):
$twitter = new Zend_Service_Twitter(array(
'username' => 'johndoe',
'accessToken' => $token
));
Then use whatever data the CMS provieds to create the 'update' post. Maybe something like this:
$status = "We just updated $projectName, check it out: $projectShortLink";
$response = $twitter->status->update($status);
Of course you'll need to make sure that's under the 140 limit.
It's pretty simple, the real overhead is setting up an 'app' and getting the oAuth token You'll need a simple one time script to request and retrieve the token (Zend's documentation gives examples) Or you could request permission for xAuth, but that seems a bit over the top for your application..
One potential benefit - since you're creating an app, you get to pick the 'via AppName' that's displayed in various clients.

Related

php - New Instagram API

I would like to implement Instagram for a Wordpress plugin.
This plugin will allow user to display instagram images with comments, likes, etc... I would like to use different source like user, tags, etc... There will be no interaction with like, comment system. It's just a plugin to display an instagram grid.
However I don't understand what is the right way to use the new API. On the instagram developer guide it's mentioned that the new API will be limited for the number of connections, etc... I don't know if it can concern my case for the plugin I want to develop.
To sum up, does the access token is enough to do what I want or do I need to use the API like this wrapper class with 'api Key', 'api Secret', 'api Callback'. It seems that information can be retrieve in different way but I don't understand what I should use. Or do I need to create an APP?
Maybe these questions can seem stupid but I'm not fluent in English and the developer guide of instagram is just not clear for me about the way I should use instagram for authentication/connection with any user.
I hope someone can guide me a little bit.
There is 2 ways you can approach this problem.
1) The plugin requires each user to register their own app with Instagram.
This means each user who installs the plugin would need to go through the app review process. Plus you would need to provide away for the users to supply their client_id, client_secret and a callback. Essentially you write the code to make everything work but the complexity of configuring the OAuth flow is still up to your users.
2) You register your plugin as an app with Instagram and make requests on your users behalf.
This is the intent of OAuth and Instagrams new API updates. This will also push all the complexity to you the plugin author. Since this is open code you will need to figure out away to keep your client_secret secure. One solution could be running a service for your plugin that handles the OAuth flow. You might also have API limit concerns depending upon your plugin adoption and usage.

Getting app user data in graph api v2, using global IDs

So version 2 of Facebook's graph API introduces app-specific IDs, to protect user privacy from spam or something like that. But they said that users who have added your app in v1 using a global ID will continue to send you their global ID in v2, to keep your app backward compatible.
This is all fine, but v2 of the api also forbids getting user data with global IDs. A call to the graph with global IDs from inside a canvas app gives an exception saying to use the app-specific ID instead.
I'm kind of at a loss here. I'm trying to get the basic information of a random subset of my app's users, to display to the current user, who isn't necessarily a friend. But most of my users have global IDs stored in my database because they joined a long time ago. It seems like if my app were new, all of the IDs stored in my database would be app-specific, and so I would be able to get their info. This indicates to me that it's not Facebook's intent to forbid me from getting the data I want. It's just impossible for me because of the unfortunate situation of having an old app.
Is there any way for me to get this data? I know I can revert to v1 of the graph but that will go away on April 30, 2015. I only want the most basic info, and I'm only displaying names.
I am using version 4 of the PHP SDK. My request looks like this:
(new FacebookRequest(
self::$session, 'GET', '',
array('ids' => implode(',', $userIds))
))->execute()->getGraphObjectList(GraphUser::className());
My session comes from calling getSession on the FacebookCanvasLoginHelper as shown in their docs, so I have a new access token and signed request.
edit
So, I rescind my question, because I'm dumb. Sahil is right. My problem was that I'm working in a separate app for testing (not an official test app, but an app I created a long time ago for testing) so the app IDs in question haven't actually added the app, so I can't get their info. Oops. Good reason to migrate to an official test app.
edit again
I un-rescind my question. Facebook is dumb. I created an official test app tied to my real app, and it is giving me an app-specific ID for myself, not the one given for the main app. I check out the page I had trouble with before, and the same exception:
Facebook\FacebookAuthorizationException: The global ID 693041250 is not allowed.
Please use the application specific ID instead.
The dev page on test apps says:
Test Apps share the same app-scoped User ID namespace as your production app making it simpler to debug issues with app-scoped IDs, or in cases where you use a copy of your production database for development.
This appears to be blatantly incorrect. I'm using a copy of my production database. I know my Facebook ID. It wouldn't even give my own ID that was given for the production app, let alone anyone else's. Does this new thing only work for brand new apps or something? I'm about ready to abandon Facebook development at this point for things like this.
You are correct in saying that-
users who have added your app in v1 using a global ID will continue to send you their global ID in v2, to keep your app backward compatible.
But this is incorrect: but v2 of the api also forbids getting user data with global IDs. A call to the graph with global IDs from inside a canvas app gives an exception saying to use the app-specific ID instead.
Of-course you'll get the user data with id returned by v2 API (be it global-id or app-specific-id).
Sorry but I don't really understand the SDK's syntax you've used (I don't like using SDKs), but I'm sure this will work. You can even test this in Graph API Explorer, just select your app from (top-middle) drop-down and call /v2/{user-id} of a v1 user and this will get you the result. You must be doing something wrong in your code.

Add users post to their facebook newsfeed automtically with php

I have a website I'm working on. It enables users to register and post stuffs within the site. Can I get a link to some sort of api that allows people to add their facebook account (once) and then automatically post what they posted on my site on their facebook newsfeed (the sort of thing that happens when you connect your facebook account to your twitter account) .I've searched and can't seem to get exactly what I want
What you want is pretty common and if you searched you clearly didn't do a good job on the search.
Using the Facebook PHP SDK is pretty straight forward. There is a PHP Library available with a demo of the functionality you want. In your case you need to do some stuff more, so I'll explain globally what you should do:
Get the Facebook PHP SDK and load it into your website, determine what scope you need to perform the actions what you are going to do, in your case you need to have access to their timeline which is called the publish_stream scope. In order to get the Facebook PHP SDK working you need to create an app at http://developers.facebook.com
If a user grants access you need to save the authentication token that the user provides and save it in your database for later use. I'm not 100% sure how long they are valid, I think it's maximum of 30 days at the moment, but you have the ability to refresh the toking in the requests you make (correct me if I'm wrong, it's been a while..)
Everytime an action is done using the Facebook API you inject the usertoken in the request, thus performing the "post" action onto their timeline.
What you are looking for is pretty straight forward and easy to find..

How to know if someone is fan of my facebook page?

I know this subject has been done already over and over. but... i must be stupid so i'll try to figure out my problem simply.
I have a facebook page, let s say that one :
http://www.facebook.com/pages/Medieval-Forgecom/302734029745018
with a few fan poeple.
now on my website i would like to give a discount to poeple who are fan of that page.
So i tried the php api (with an application id and secret) before discovering that this is NOT what i want as my page is not an app and has no appId neither secret. Am i misunderstanding something here?
So i m wondering how in php i can know if someone is fan or not...
If it is not possible i could use the javascript api to make this check ( wich is quite bad, it should be done somewhere via php) but even this way i get trouble with the deprecated api and the code refering to javascript inside the facebook website.
in a nutshell, i'm lost.
thanks for your time and attention.
Do some research on the concept of "fan-gate". I think this is what you're looking for.
https://www.facebook.com/note.php?note_id=10150130919053430
http://www.youtube.com/watch?v=fBBnrtG0hAw
There are three ways of using Facebook API. Social plugins are widgets such as comments or like buttons. You can put them into your site directly and easily. And then there is the Graph API. First way of using this API is to create a whole standalone Facebook application, such as Farmwille. Second way is to use it only at your site, out of the Facebook frame. Regardless of the type of your usage, you need to register an application on Facebook, so Facebook API can authorize you. Without that you can't use the API. You don't need to create a real standalone app if you want only to use the API at your own site, but you must register it and this registration is just called Facebook application. It can be virtual application representing your site.

Is there a simple method using PHP for posting to Twitter without managing user logins or getting tweets?

I've seen there is some other discussion about this, however, none of the other threads I've read have targetted my situation.
For one, I do not need to get any Tweets from Twitter. I only need to send to Twitter.
For another, I don't need to have multiple accounts or different Twitter users. I can already ensure the page will only be seen by the one authorized user, so I can save any necessary login information in one configuration file and be done.
I am only posting occasionally from one web site, to one Twitter feed, and only one user will be logged onto the the web site that will send the tweet.
I am hoping to find a simple tutorial or script that can allow me to cut to the bare bones and just send tweets to my Twitter account.
However, all the tutorials and scripts I've seen so far have been too elaborate, handling logins, sessions, authenticating multiple users, and so on.
Is there any way I can get simple oAuth PHP code to accomplish what I'm describing?
This would help
http://code.google.com/p/dabr/source/browse/trunk/common/twitter.php
http://code.google.com/p/dabr/source/browse/trunk/common/OAuth.php
This should help or at least point you in the right direction.
https://dev.twitter.com/docs/twitter-libraries#php
You can use ZF component
get accessToken only once, keep it as serialized string anywhere
http://framework.zend.com/manual/en/zend.service.twitter.html

Categories