Categories
discuss

Picasso library stopped working today with facebook graph picture links

In my app i use Picasso library to load images from urls. It is a nicely working easily importable and usable library, and just do the thing i need.

However, today it stopped working, and not while developping it is stopped working on a compiled apk.

So after i searched and searched for the reason i just found this buggy thing:

I use facebook graph urls to load profile pictures.

Here is one like: profile pictre,

the link is actually “http://graph.facebook.com/1464090949/picture?type=large

But it is redirecting to: https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t5.0-1/572518_1464090949_1222130273_n.jpg

Of course, both of url calls working in a browser, and you can see the profile picture.

However when i test both links with Picasso:

    ImageView iv = (ImageView)findViewById(R.id.imageView1);

    //Url1 NOT working, loads nothing.
    String url1 = "http://graph.facebook.com/1464090949/picture?type=large";

    //Url2 is the same as URL1, i just copied it from a browser, and this is working
    String url2 = "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t5.0-1/572518_1464090949_1222130273_n.jpg";


    Picasso.with(this).load(url2).into(iv);

So the conclusion is, facebook maybe changed something and from now on Picasso cannot load images from graph.

Anybody can suggest me something to make this work? Of course i can try different libraries but if there is an other way i would be really happy.

Answer

Workaround1:

Change to https from http.

Working: https://graph.facebook.com/1464090949/picture?type=large

Not Working: http://graph.facebook.com/1464090949/picture?type=large

Workaround2:

Found soulution on this topic.

If you want for example: http://graph.facebook.com/1464090949/picture?type=large

This profile picture you could use:

https://graph.facebook.com/1464090949/?fields=picture.type(large)

Which returns a JSON Object:

   {
   "id": "1464090949",
   "picture": {
      "data": {
         "url": "https://fbcdn-profile-a.akamaihd.net/hprofile-ak-prn1/t5.0-1/572518_1464090949_1222130273_n.jpg",
         "is_silhouette": false
      }
   }
}

And tada! There it is. url’s key is the redirected url you can use to load your images.

(This will need oAuth which i didnt tested, just stick with Workaround1)

Categories
discuss

What is the time complexity of String.toCharArray(), O(n) or O(1)

Suppose you want to convert a String of length n to a character array of length n.

char [] chArray = someString.toCharArray();

What is the computation complexity?O(n) or O(1) ( n: length of someString)

I am under the impression that all it does is to allocate memory of size n*sizeof(char) and make a copy of that string to that location. So copying n cells of memory takes O(n) time. Is it ?

or it could be O(1), ( simple pointer relocation or as mentioned here)?

Answer

The answer is linear time.

Think of it as copying single char and putting it into an array. It depends on number of elements so it’s O(n).

Categories
discuss

java.lang.SecurityException: attempting to read gservices without permission

I have recently changed from adMob 6.4.1 to Google Play Services rev 15 and have just received notice of a new crash report that I do not understand:

java.lang.SecurityException: attempting to read gservices without permission: Neither user 10158 nor current process has com.google.android.providers.gsf.permission.READ_GSERVICES.
at android.os.Parcel.readException(Parcel.java:1425)
at android.os.Parcel.readException(Parcel.java:1379)
at xs.a(SourceFile:133)
at xo.a(SourceFile:133)
at xo.a(SourceFile:118)
at ud.d(SourceFile:88)
at ud.b(SourceFile:129)
at ua.a(SourceFile:239)
at ua.a(SourceFile:176)
at aas.a(SourceFile:118)
at abz.run(SourceFile:14)
at acb.run(SourceFile:30)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:856)

I did some research, and all the results are either outdated, or are related to Google+ / Google Maps, neither of which I use in the app.

I’ve never read anywhere in the GPS Developer guide for adMob that I needed to add the READ GSERVICES permission…

Anyone know what this is about?

Answer

This issue was introduced with the latest release of the Google Play Services (v4.3) on the android devices. Google is aware about it and it will be fixed in a future version (not the next one…)

https://groups.google.com/forum/#!topic/google-admob-ads-sdk/sePctoDJbRg%5B101-125-false%5D

Categories
discuss

findAndModify – MongoError: exception: must specify remove or update

Id like to update an array and return the doc. Is my findAndModify syntax correct?

this.becomeFollower = function(title, username, callback){
    "use strict"

    posts.findAndModify({
        query: {"title":title, "roster":"yes"},
        update: { "$addToSet": { "followers":username } },
        new: true,
        upsert: true
        }, 
        function(err, doc){
            console.log('find and modified  ' +doc);
        });

}

I had no problem using this:

    posts.update({"title":title, "roster":"yes"}, { "$addToSet": { "followers":username } }, function(err, roster){
        "use strict"
        if(err) return callback(err, null);
        callback(err, roster);
    });

Answer

Check out the docs for node-mongodb findAndModify; the signature looks like:

collection.findAndModify(query, sort, update, options, callback)

So you should do:

  posts.findAndModify(
    {"title":title, "roster":"yes"},
    [['_id','asc']],
    { "$addToSet": { "followers":username } },
    {new: true, upsert: true}, 
    function(err, doc){
        console.log('find and modified  ' +doc);
    }
  );

The sort argument is probably optional, but it’s unclear so I included it in the example.

Categories
discuss

Mockito swallows up stack trace?

Why does Mockito swallow up stack traces? For example, if I have a

public class Foo
{
    public void foo()
    {
        bar();
    }

    public void bar()
    {
        baz();
    }

    public void baz()
    {
        throw new RuntimeException();
    }
}

and a test such as

public class MockTest
{
    @Test
    public void test()
    {
        Mockito.spy(new Foo()).foo();
    }
}

the exception thrown always looks like

java.lang.RuntimeException
    at Foo.baz(Foo.java:17)
    at MockTest.test(MockTest.java:11)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

** So, where is all the stuff between

Foo.baz(Foo.java:17)
MockTest.test(MockTest.java:11)

?

(The example provided here is a just a simplification — I’m dealing with a lot more indirections, classes, and so forth. I can’t have Mockito swallowing up the critical parts of a partial mock stack trace…)

Answer

YES, mockito cleans stacktraces !

The piece of code at work StackTraceFilter

There are different ways to disable that

  • Since Mockito 1.10.10, provide your own StackTraceCleanerProvider via the mockito extension mechanism (create a resource file mockito-extensions/org.mockito.plugins.StackTraceCleanerProvider with the qualified name of your implementation)

  • Override the cleansStackTrace method in a custom IMockitoConfiguration, look there for more information.

Source: stackoverflow
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Privacy Policy, and Copyright Policy. Content is available under CC BY-SA 3.0 unless otherwise noted. The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 © No Copyrights, All Questions are retrived from public domain..